Skip to content

Fragments not working #1

@basilfx

Description

@basilfx

First of all: thank you for contributing this! Django is great, GraphQL is great, but Relay was too much for me.

I noticed that queries with fragments are not yet supported. For instance:

query Objects {
  object {
    results(offset: 0, limit: 20) {
      ...ObjectFragment
    }
    totalCount
  }
}

fragment ObjectFragment on ObjectType {
  id
  __typename
}

I have worked around the issue by changing utils.py on line 105, since it looks like that method only optimizes the query:

...
elif hasattr(field, 'selection_set') and field.selection_set:
...

I found something that might help here. See the get_fields method.

Here is a traceback:

Traceback (most recent call last):
  File "/env/lib/python3.6/site-packages/graphql/execution/executor.py", line 191, in resolve_or_error
    return executor.execute(resolve_fn, source, info, **args)
  File "/env/lib/python3.6/site-packages/graphql/execution/executors/sync.py", line 7, in execute
    return fn(*args, **kwargs)
  File "/env/lib/python3.6/site-packages/graphene_django/debug/middleware.py", line 56, in resolve
    promise = next(root, info, **args)
  File "/env/lib/python3.6/site-packages/graphql/execution/middleware.py", line 57, in make_it_promise
    return Promise.resolve(next(*a, **b))
  File "/env/lib/python3.6/site-packages/graphene_django_extras/fields.py", line 229, in list_resolver
    qs = queryset_factory(manager, info.field_asts, filtering_args, **kwargs)
  File "/env/lib/python3.6/site-packages/graphene_django_extras/utils.py", line 131, in queryset_factory
    select_related, prefetch_related = recursive_params(fields_asts[0].selection_set, available_related_fields, select_related, prefetch_related)
  File "/env/lib/python3.6/site-packages/graphene_django_extras/utils.py", line 106, in recursive_params
    a, b = recursive_params(field.selection_set, available_related_fields, select_related, prefetch_related)
  File "/env/lib/python3.6/site-packages/graphene_django_extras/utils.py", line 105, in recursive_params
    elif field.selection_set:
AttributeError: 'FragmentSpread' object has no attribute 'selection_set'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions