Skip to content
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

Enabling @deprecated at runtime leads to validation failure #2573

Open
AnatolyTsapin opened this issue Mar 1, 2023 · 0 comments
Open

Enabling @deprecated at runtime leads to validation failure #2573

AnatolyTsapin opened this issue Mar 1, 2023 · 0 comments
Labels
federation Related to Apollo federation

Comments

@AnatolyTsapin
Copy link

What happened?

I wanted to have a hook on @deprecated directive at runtime. So I added skip_runtime: false option for this directive. This led to error during validation:

validation failed: packages.Load: graph/generated.go:661:21: ec.directives.Deprecated undefined (type DirectiveRoot has no field or method Deprecated)
graph/generated.go:664:25: ec.directives.Deprecated undefined (type DirectiveRoot has no field or method Deprecated)

exit status 1

What did you expect?

It was expected Deprecated field to be generated in DirectiveRoot structure, but it was filtered out by func (d *Data) Directives() [DirectiveList.

Minimal graphql.schema and models to reproduce

I've used steps from Getting Started for reproduction but with the following changes:

gqlgen.yml

# Where are all the schema files located? globs are supported eg  src/**/*.graphqls
schema:
  - graph/*.graphqls

# Where should the generated server code go?
exec:
  filename: graph/generated.go
  package: graph

# Uncomment to enable federation
# federation:
#   filename: graph/federation.go
#   package: graph

directives:
  deprecated:
    skip_runtime: false

# Where should any generated models go?
model:
  filename: graph/model/models_gen.go
  package: model

# Where should the resolver implementations go?
resolver:
  layout: follow-schema
  dir: graph
  package: graph

# Optional: turn on use ` + "`" + `gqlgen:"fieldName"` + "`" + ` tags in your models
# struct_tag: json

# Optional: turn on to use []Thing instead of []*Thing
# omit_slice_element_pointers: false

# Optional: turn off to make struct-type struct fields not use pointers
# e.g. type Thing struct { FieldA OtherThing } instead of { FieldA *OtherThing }
# struct_fields_always_pointers: true

# Optional: turn off to make resolvers return values instead of pointers for structs
# resolvers_always_return_pointers: true

# Optional: set to speed up generation time by not performing a final validation pass.
# skip_validation: true

# gqlgen will search for any type names in the schema in these go packages
# if they match it will use them, otherwise it will generate them.
autobind:
#  - "test/graph/model"

# This section declares type mapping between the GraphQL and go type systems
#
# The first line in each type will be used as defaults for resolver arguments and
# modelgen, the others will be allowed when binding to fields. Configure them to
# your liking
models:
  ID:
    model:
      - github.com/99designs/gqlgen/graphql.ID
      - github.com/99designs/gqlgen/graphql.Int
      - github.com/99designs/gqlgen/graphql.Int64
      - github.com/99designs/gqlgen/graphql.Int32
  Int:
    model:
      - github.com/99designs/gqlgen/graphql.Int
      - github.com/99designs/gqlgen/graphql.Int64
      - github.com/99designs/gqlgen/graphql.Int32

graph/schema.graphqls

# GraphQL schema example
#
# https://gqlgen.com/getting-started/

type Todo {
  id: ID!
  text: String!
  done: Boolean! @deprecated(reason: "for test")
  user: User!
}

type User {
  id: ID!# GraphQL schema example
#
# https://gqlgen.com/getting-started/

type Todo {
  id: ID!
  text: String!
  done: Boolean! @deprecated(reason: "for test")
  user: User!
}

type User {
  id: ID!
  name: String!
}

type Query {
  todos: [Todo!]!
}

input NewTodo {
  text: String!
  userId: String!
}

type Mutation {
  createTodo(input: NewTodo!): Todo!
}

  name: String!
}

type Query {
  todos: [Todo!]!
}

input NewTodo {
  text: String!
  userId: String!
}

type Mutation {
  createTodo(input: NewTodo!): Todo!
}

versions

  • go run github.com/99designs/gqlgen version v0.17.25
  • go version go1.19.5 darwin/arm64
@StevenACoffman StevenACoffman added the federation Related to Apollo federation label May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
federation Related to Apollo federation
Projects
None yet
Development

No branches or pull requests

2 participants