99designs/gqlgen

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

オープン

#1,138 opened on 2020/04/08

 (13 件のコメント) (6 件のリアクション) (0 人の担当者)Go (1,250 件のフォーク)auto 404
federationhelp wanted

Repository metrics

Stars
 (10,737 個のスター)
PR merge metrics
 (平均マージ 11d) (30d で 20 merged PRs)

説明

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

コントリビューターガイド