99designs/gqlgen

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

Open

#1,138 opened on Apr 8, 2020

View on GitHub
 (13 comments) (6 reactions) (0 assignees)Go (1,250 forks)auto 404
federationhelp wanted

Repository metrics

Stars
 (10,737 stars)
PR merge metrics
 (PR metrics pending)

Description

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

Contributor guide