99designs/gqlgen

Support for nested selection sets on _FieldSet (on @requires annotation)

Aperta

#1138 aperta il 8 apr 2020

 (13 commenti) (6 reazioni) (0 assegnatari)Go (1250 fork)auto 404
federationhelp wanted

Metriche repository

Star
 (10.737 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

What happened?

We started using federation for our graphql solution. In our setup we have two graphql services, one providing items, another extending the item with breadcrumb information. In order to be able to resolve the breadcrumb information we need the id of a nested type on Item, i.e., the Variant of the Item.

According to the apollo federation specifications on the Scalar _FieldSet, it supports nested selection sets as in "variant { id }" (https://www.apollographql.com/docs/apollo-server/federation/federation-spec/#scalar-_fieldset). This does not seem to be supported by gqlgen.

I observed that gqlgen is parsing the @requires annotation argument as being 4 fields, i.e., variant, {, id and } thereby ignoring that variant has a nested selection set defined. gqlgen execution crashes at some point with: federation: federation.gotpl: template: federation.gotpl:53:50: executing "federation.gotpl" at <.TypeReference.UnmarshalFunc>: error calling UnmarshalFunc: runtime error: invalid memory address or nil pointer dereference%

What did you expect?

That gqlgen generation works for a federation setup when having the schema setup as below.

Minimal graphql.schema

service 1:

type Item @key(fields: "id") {
     id: ID!
     variant: Variant
}
type Variant {
     id: ID!
}

service 2:

extend type Item @key(fields: "id") {
     id: ID! @external
     variant: Variant @external 
     breadcrumbs: [String!]! @requires(field: "variant { id }")
}
extend type Variant {
     id: ID! @external
}

versions

  • gqlgen version: v0.11.3
  • go version 1.13.8

Guida contributor