0

I am trying to define a GraphQL directive which has an array argument which looks like this:

input Data {
    someField: String!
    anotherField: String!
}
directive @someDirective( args: [Data!]! ) on OBJECT

type SomeType @someDirective( args: [{someField: "blah", anotherField: "blah"}] ) 
    {
    empty: String
}

If I change Data to be a type, the GraphQL compiler get the error:

"The type of @someDirective(args:) must be Input Type but got: [Data!]!."

The problem with using input is that there is no validation of the input by the compiler. This compiles fine:

type AnotherType @someDirective( args: [{blah: "blah", blah2: "blah"}] ) 
    {
    empty: String
}

Is it possible to define an object array argument for a directive which gets validated by the compiler?

jmc42
  • 359
  • 5
  • 22
  • You can refer to [this detailed answer](https://stackoverflow.com/a/55881719/19328934), for somewhat similar question – Gil Gardosh Sep 04 '22 at 09:01
  • I think this case is covered by [that detailed answer](https://stackoverflow.com/questions/41743253/whats-the-point-of-input-type-in-graphql/55881719#55881719) – Gil Gardosh Sep 04 '22 at 14:02
  • Not sure it covers the case, as it is not discussing schema directives specifically. I get the feeling that the compiler cannot distinguish between schema and input directives; if it did, it might allow Object types in schema directives. I guess the reason why the compiler allows syntax errors in the schema is because it is not type checking use of input types? – jmc42 Sep 05 '22 at 11:09

0 Answers0