`oneOf` directive usage does not appear in introspection
Describe the Bug
When introspecting a schema, there is no indication that the oneOf schema directive is used for a specific type. This leads to issues when, among other things, using the introspection API to perform codegen activity https://the-guild.dev/graphql/codegen/docs/config-reference/schema-field#url
Additional Context
(original post: https://the-guild.dev/graphql/codegen/docs/config-reference/schema-field#url)
I have a @strawberry.input(one_of=True) class
@strawberry.input(one_of=True)
class InputWithOneOf:
string: strawberry.Maybe[str]
boolean: strawberry.Maybe[bool]
when I generate the .graphql file via export_schema, the result has the @oneOf embedded in it
input InputWithOneOf @oneOf {
string: String
boolean: Boolean
}
If i codegen against this file, I get this graphql.ts
export type InputWithOneOf =
{ boolean: Scalars['Boolean']['input']; string?: never; }
| { boolean?: never; string: Scalars['String']['input']; };
however, when I attempt to generate the equivalent from introspection, using https://github.com/prisma-labs/get-graphql-schema, it omits @oneOf
input InputWithOneOf {
string: String
boolean: Boolean
}
... leading to this less-specific graphql.ts
export type InputWithOneOf = {
boolean?: InputMaybe<Scalars['Boolean']['input']>;
string?: InputMaybe<Scalars['String']['input']>;
};
I am attempting to do graphql-codegen for my schema; my preferred workflow in my development environment is to codegen against my local /graphql endpoint rather than via a file-based method. However, I also have a CI step that instead uses a file-based approach (via export_schema) to verify the data is in sync.
Ideally, I am able to get consistent output for codegen purposes between introspection via API and the .graphql document exported schema.
Hey @kevinmsun, we implemented custom support for oneOf in strawberry before the support in graphql-core came out. Custom directives never appear in introspection. Have you tried with the official oneOf release in the latest graphql-core alpha (for example v3.3.0a9)? 😊
@erikwrede I think we might need to do some work to make @oneOf show in the exported schema in GraphQL-core alpha 🤔
@patrick91 it was implemented upstream in JS Last Summer. Let me double check the relevant code path is already ported
GraphQL JS PR: https://github.com/graphql/graphql-js/pull/4078 -> not in graphql-core yet. on it
@erikwrede it is there 😊 https://github.com/graphql-python/graphql-core/commit/b7a18ed48b7d97a79c2d0db5a8b53d820c67b8d2
but we don't use that directly (we made our custom thing) 😊
@patrick91 yea, but we still need to add support in the introspection anyhow: https://github.com/graphql-python/graphql-core/pull/241
I can work on switching our custom thing over to the core implementation though if the version matches. Do we have a central place for feature toggles based on graphql core version yet? Think that would be useful
I can work on switching our custom thing over to the core implementation though if the version matches. Do we have a central place for feature toggles based on graphql core version yet? Think that would be useful
no we don't, unfortunately