Closed ArrayKnight closed 3 years ago
Another possibility would be to write unknown
in place of the missing type. Though a warning in CLI would also be nice
Thank you for reporting this @ArrayKnight . I'm not sure I fully understand this concept of private/public here. If an interface isn't being published as part of the schema, it should fail in codegen due to a missing type during the validation phase. Can you please share a live reproduction of this issue?
I don't have any immediate time to setup an environment, but I can describe it in a more specific example:
We're using Craft CMS as a headless CMS, so we bought a Pro license, enabled the GraphQL interface and got to modeling our data.
Now, when you do a schema codegen you'll end up with something like:
type Query {
entry(
# ...removed for clarity
): EntryInterface
entries(
# ...
): [EntryInterface]
}
type AssetInterface { # Oddly present despite not being part of the public schema
#...
}
type page_page_Entry implements ElementInterface & EntryInterface {
images(
# ...
): [AssetInterface]
}
So, then you would write a query:
query Page($uid: [String]){
entry(uid: $uid) {
... on page_page_Entry {
images {
url
}
}
}
}
fragment Section on section_BlockType {
tiles {
... on tiles_BlockType {
tileImage { # also an assets field
uid
url
}
}
}
}
And what's interesting is that you will find AssetInterface as a top level type and you'll even find it referenced within top level types that have asset fields, but when you have a fragment that references that interface you get invalid syntax:
export type AssetInterface = {
// ...
}
export type Page_Page_Entry = ElementInterface & EntryInterface & {
// ...
images: Maybe<Array<Maybe<AssetInterface>>>;
}
export SectionFragment = (
{ __typename: 'section_BlockType ' } &
{ tiles: Maybe<Array<Maybe<(
{ __typename: 'tiles_BlockType' } &
{ tileImage: Maybe<Array<Maybe<>>> } // <-- Invalid syntax
)}
)
To remedy this, I had to go to the GraphQL Public Schema, check Assets, and hit save.
Closing, @ArrayKnight . This was related to missing config right?
@dotansimha I disagree that this should be closed.
I can see the argument that this is a setting in Craft CMS that causes this issue, however, I feel like the codegen tool should handle this case by either throwing an error in CLI or replacing the missing type with unknown
and warning in the CLI.
I see, but I'm not familiar with CraftCMS, or with the exact setup that you have, and you are not able to create a complete reproduction. I don't have any tools to reproduce or investigate it. I'm willing to try to solve that, but I will need your cooperation... Please share a reproduction and then I'll re-open this.
Describe the bug When a public query would return a private interface (due to a mistake in the public schema), the Codegen CLI "successfully" completes, but creates a type definition file with invalid (syntactically incorrect) types/interfaces (
Maybe<Array<Maybe<>>>
).To Reproduce Steps to reproduce the behavior:
codegen.yml
config file:src/graphql/index.tsx
:Expected behavior Codegen CLI should throw an error detailing that there is a missing/private type that it can't write and then not output a file
Environment: