graphql-kit / graphql-faker

🎲 Mock or extend your GraphQL API with faked data. No coding required.
MIT License
2.68k stars 225 forks source link

`@deprecated` directive not supported for input field #186

Open steliosrammos opened 1 year ago

steliosrammos commented 1 year ago

GraphQL-Faker throws an error when running on a schema that contains a @deprecated directive on an input field. However that is now supported by the graphql-spec, see: https://github.com/graphql/graphql-spec/pull/805

Logs:

graphql-faker            | 
graphql-faker            | Your schema constains 2 validation errors: 
graphql-faker            | 
graphql-faker            | Directive "deprecated" may not be used on INPUT_FIELD_DEFINITION.
graphql-faker            | 
graphql-faker            | schema.sdl:261:19
graphql-faker            | 260 |   description: description_String_maxLength_2200
graphql-faker            | 261 |   active: Boolean @deprecated(reason: "this field will soon be replaced by the status field")
graphql-faker            |     |                   ^
graphql-faker            | 262 |   draft: Boolean @deprecated(reason: "this field will soon be replaced by the status field")
graphql-faker            | 
graphql-faker            | 
graphql-faker            | Directive "deprecated" may not be used on INPUT_FIELD_DEFINITION.
graphql-faker            | 
graphql-faker            | schema.sdl:262:18
graphql-faker            | 261 |   active: Boolean @deprecated(reason: "this field will soon be replaced by the status field")
graphql-faker            | 262 |   draft: Boolean @deprecated(reason: "this field will soon be replaced by the status field")
graphql-faker            |     |                  ^
graphql-faker            | 263 |   expiresAt: String
graphql-faker            | 
Xample commented 1 year ago

The directive declared for faker are only the one related to faker i.e.

directive @fake(
    type: fake__Types!
    options: fake__options = {}
    locale: fake__Locale
) on FIELD_DEFINITION | SCALAR
directive @listLength(min: Int!, max: Int!) on FIELD_DEFINITION
scalar examples__JSON
directive @examples(values: [examples__JSON]!) on FIELD_DEFINITION | SCALAR

Therefore, to support the @deprecated directive, try adding the following definition somewhere in your schema

directive @deprecated(
  reason: String = "No longer supported"
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE
andrenascentes commented 1 year ago

I run into the same problem. I've tried @Xample solution but it gives me following error: Directive "deprecated" already exists in the schema. It cannot be redefined.. Worth pointing that this directive is not declared anywhere else. I've put the declaration as the first thing is the schema file. Any workaround?

Xample commented 1 year ago

Check carefully the included files, you might be importing both a source and a generated .GraphQL file which leads to this duplicated directive error.