Skip to content

Fragment on <interface> not working #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Sander0542 opened this issue Aug 8, 2022 · 9 comments
Closed

Fragment on <interface> not working #158

Sander0542 opened this issue Aug 8, 2022 · 9 comments

Comments

@Sander0542
Copy link

Sander0542 commented Aug 8, 2022

When I am using a fragment which implements on an interface, the query doesn't get generated with that part

interface IUser {
    id: ID!
}

type User implements IUser {
    id: ID!
}

type Location {
    id: ID!

    users: [User!]!
}

type Query {
    locations: [Location!]!
}

fragment UserSummary on IUser {
    id
}

fragment LocationWithUsers on Location {
    id
    users {
        ...UserSummary
    }
}

query GetLocations {
    locations {
        ...LocationWithUsers
    }
}
budde377 added a commit that referenced this issue Aug 9, 2022
@budde377
Copy link
Contributor

budde377 commented Aug 9, 2022

Thanks for reporting this. I haven't been able to reproduce your issue (please take a look at the referenced PR). You do seem to have an error in your fragment as well:

fragment PersonSummary on IPerson {
  id: ID!
}

should probably be

fragment PersonSummary on IPerson {
  id
}

Some information that might be useful to help me help you is:

  • What version of graphql_codegen are you using?
  • Examples of generated code
  • Potential build errors.

budde377 added a commit that referenced this issue Aug 9, 2022
@Sander0542
Copy link
Author

Sander0542 commented Aug 9, 2022

graphql_codegen version: 0.10.3

Sorry, the schema I proved works. It happens when I am using nested fragments.

interface IUser {
    id: ID!
}

type User implements IUser {
    id: ID!
}

type Location {
    id: ID!

    users: [User!]!
}

type Query {
    locations: [Location!]!
}

fragment UserSummary on IUser {
    id
}

fragment LocationWithUsers on Location {
    id
    users {
        ...UserSummary
    }
}

query GetLocations {
    locations {
        ...LocationWithUsers
    }
}

(I updated the schema on the initial post too)

When the query is sent to the server, it doesn't contain all the required properties from the person summary except the __typename


When I add the id field to the fragment it works.

fragment LocationWithUsers on Location {
    id
    users {
        id
        ...UserSummary
    }
}

@Sander0542
Copy link
Author

I have a feeling this comment could be the issue zino-hofmann/graphql-flutter#994 (comment)

@budde377
Copy link
Contributor

budde377 commented Aug 9, 2022

So is this a problem with the data not being sent to/from your server on runtime, or the built serialisers?

@Sander0542
Copy link
Author

The query that gets sent to the server doesn't contain the required information like users.id

@budde377
Copy link
Contributor

budde377 commented Aug 9, 2022 via email

@Sander0542
Copy link
Author

Sander0542 commented Aug 9, 2022

The query that should get sent to the server is

query GetLocations {
  locations {
    __typename
    users {
       __typename
      id
    }
  }
}

But the query that is sent is

query GetLocations {
  locations {
    __typename
    users {
      __typename
    }
  }
}

@budde377
Copy link
Contributor

budde377 commented Aug 9, 2022

Cheers. The library does no such changes to queries.

Please make sure you've rebuild your serialisers. If this doesn't work please share the generated file + the original query + an example on how you're calling the query.

@budde377
Copy link
Contributor

I'm going to close this issue for now. Let's revisit if you have more information.

@budde377 budde377 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants