99designs / 99designs/gqlgen

Enabling @deprecated at runtime leads to validation failure

Abierto
#2,573 0 comentarios 1 reacción 0 asignados Ver en GitHub
federation
Lenguaje dominante
Go
Estrellas
10.8k
Forks
1.3k
Merge medio
2 d 36 min
PR fusionados (30 d)
26

Descripción

### 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`](https://github.com/99designs/gqlgen/blob/master/codegen/data.go#L67).

### Minimal graphql.schema and models to reproduce

I've used steps from [Getting Started](https://gqlgen.com/getting-started/) for reproduction but with the following changes:

#### gqlgen.yml
```yaml
# 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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.