def create_resolve_info(schema, request_string, variables=None, user=None):
    exe_context = create_execution_context(schema, request_string, variables,
                                           user)
    parent_type = get_operation_root_type(schema, exe_context.operation)
    field_asts = get_field_asts_from_execution_context(exe_context)

    field_ast = field_asts[0]
    field_name = field_ast.name.value

    field_def = get_field_def(schema, parent_type, field_name)
    if not field_def:
        return Undefined
    return_type = field_def.type

    # The resolve function's optional third argument is a context value that
    # is provided to every resolve function within an execution. It is commonly
    # used to represent an authenticated user, or request-specific caches.
    context = exe_context.context_value
    return ResolveInfo(field_name,
                       field_asts,
                       return_type,
                       parent_type,
                       schema=schema,
                       fragments=exe_context.fragments,
                       root_value=exe_context.root_value,
                       operation=exe_context.operation,
                       variable_values=exe_context.variable_values,
                       context=context)
Example #2
0
 def optimize(self, queryset):
     info = self.root_info
     field_def = get_field_def(info.schema, info.parent_type, info.field_name)
     store = self._optimize_gql_selections(
         self._get_type(field_def),
         info.field_asts[0],
         # info.parent_type,
     )
     return store.optimize_queryset(queryset)
Example #3
0
    def optimize(self, queryset):
        info = self.root_info
        field_def = get_field_def(info.schema, info.parent_type,
                                  info.field_name)
        store = self._optimize_gql_selections(
            self._get_type(field_def),
            info.field_asts[0],
            # info.parent_type,
        )

        # For matching prefetched lists with their parent,
        # the foreign key will be used.
        # Force inclusion of parent_id_field if specified.
        if self.parent_id_field:
            store.append_only(self.parent_id_field)

        return store.optimize_queryset(queryset)
Example #4
0
    def optimize(self, queryset, append_only=None):
        info = self.root_info
        field_def = get_field_def(info.schema, info.parent_type, info.field_name)
        store = self._optimize_gql_selections(
            self._get_type(field_def),
            info.field_asts[0],
            # info.parent_type,
        )
        if self.parent_id_field:
            store.append_only(self.parent_id_field)

        if hasattr(queryset, '_gql_parent_id_field'):
            store.append_only(getattr(queryset, '_gql_parent_id_field'))

        # Allow forcing attributes in only.
        if append_only:
            store.append_only_list += append_only

        return store.optimize_queryset(queryset)