Skip to content

derive(GraphQLQuery) fails when query contains fragments which refer to other fragments #286

Closed
@cairomassimo

Description

@cairomassimo

derive(GraphQLQuery) sometimes fails when the query contains a fragment which refers to a second fragment.
The error is due to the response struct for the innermost fragment not being generated, causing error[E0412]: cannot find type <innermost fragment name> in this scope.
This problem seems to happen only if the name of the innermost fragment is lexicographically smaller than the name of the containing fragment.

This is the smallest example illustrating the issue:

src/schema.graphql:

type Query { x: String }

src/query-good.graphql:

query Q { ...FragmentA }
fragment FragmentA on Query { ...FragmentB }
fragment FragmentB on Query { x }

src/query-bad.graphql:

query Q { ...FragmentB }
fragment FragmentB on Query { ...FragmentA }
fragment FragmentA on Query { x }

src/lib.rs:

extern crate graphql_client;
extern crate serde;

use graphql_client::GraphQLQuery;

#[derive(GraphQLQuery)]
#[graphql(
    schema_path = "src/schema.graphql",
    query_path = "src/query-bad.graphql"
)]
struct Q;

When running cargo build:

[...]
error[E0412]: cannot find type `FragmentA` in this scope
 --> src/lib.rs:6:10
  |
6 | #[derive(GraphQLQuery)]
  |          ^^^^^^^^^^^^ help: a struct with a similar name exists: `FragmentB`
[...]

Replacing query-bad.graphql with query-good.graphql it compiles successfully.

Version 0.8.0.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions