playlyfe / go-graphql

A powerful GraphQL server implementation for Golang
248 stars 20 forks source link

Introspection: Skip/Include Directive Locations #40

Open fungl164 opened 5 years ago

fungl164 commented 5 years ago

Some newer apps complain about missing locations when placing an IntrospectionQuery request.

A quick fix is to add the following to the directive's definition object in the schema.go file:

"locations":   []string{"FIELD", "FRAGMENT_DEFINITION", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"},

Below is an example where it would be placed...

schema.go (lines 269-315)

result := map[string]interface{}{
  "queryType": executor.introspectType(params, queryRoot),
  "directives": []map[string]interface{}{
    {
      "name":        "skip",
      "description": "Conditionally exclude a field or fragment during execution",
      "args":        []map[string]interface{}{ ... },
      "locations":   []string{"FIELD", "FRAGMENT_DEFINITION", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"},
      "onOperation": false,
      "onField":     true,
      "onFragment":  true,
    },
    ...
  },
}

schema.go (lines 88-96)

const INTROSPECTION_SCHEMA = `
...
type __Directive {
  name: String!
  description: String
  args: [__InputValue!]!
  locations: [String!]!
  onOperation: Boolean!
  onFragment: Boolean!
  onField: Boolean!
}
...
`