You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to define a fragment on the "Error" interface. In the actual code we have multiple different error classes implementing this same interface, here I have included a minimal example. I'm not allowed to share the actual code.
The query below works from the graphql UI but ariadne-codegen doesn't generate the right code.
interface Error {
type: String
title: String
status: Int
detail: String
instance: String
}
type DeletionError implements Error {
type: String
title: String
status: Int
detail: String
instance: String
}
type DeleteThingPayload {
thing: Thing
errors: [DeletionError!]
}
type Thing {
id: ID!
name: String
}
input DeleteThingInput {
id: ID!
}
type Mutation {
deleteThing(input: DeleteThingInput!): DeleteThingPayload!
}
Contents of queries.graphql:
fragment DefaultError on Error {
... on Error {
type
title
status
detail
instance
}
}
mutation MyDeleteThing($id: ID!) {
deleteThing (input: {id: $id}) {
thing {
id
name
}
errors {
__typename
... DefaultError
}
}
}
When running ariadne-codegen, I expect to see all the error fields (type, title etc.) defined for the deleteThing query.
But instead only __typename is defined. Here's the relevant part of the generated code:
class MyDeleteThingDeleteThingErrors(BaseModel):
typename__: Literal["DeletionError"] = Field(alias="__typename")
Inputs that work
Modifying the fragment to use the specific error type (DeletionError) works:
fragment DefaultError on DeletionError {
... on DeletionError {
type
title
status
detail
instance
}
}
To me the changed working version looks like the way to do it but maybe I'm wrong given that it works in the UI. See the examples here f.ex. that has the title from the interface outside the spread and only spreads on concrete specific fields. Same here in the GraphQL docs where you only need spreading to get fields from the concrete types. So I usually do:
fragment <Fragment> on <Interface> {
interfaceFieldanotherInterfaceField...on <ConcreteType> {
customFieldOnlyOnInterfaceImpl
}
...on <AnotherConcreteType> {
anotherCustomFieldOnlyOnAnotherInterfaceImpl
}
}
By doing this it should still work in the UI and generate the proper code, right?
So imagining DeletionError had a specific field not on the interface called deleteFailReason I would write something like this and then just add more spreads for the other custom fields:
Ariadne-codegen version: 0.11.0
I'm trying to define a fragment on the "Error" interface. In the actual code we have multiple different error classes implementing this same interface, here I have included a minimal example. I'm not allowed to share the actual code.
The query below works from the graphql UI but ariadne-codegen doesn't generate the right code.
Inputs that don't work
pyproject.toml configuration:
Contents of schema.graphql:
Contents of queries.graphql:
When running ariadne-codegen, I expect to see all the error fields (type, title etc.) defined for the deleteThing query.
But instead only __typename is defined. Here's the relevant part of the generated code:
Inputs that work
Modifying the fragment to use the specific error type (DeletionError) works:
Resulting code:
The text was updated successfully, but these errors were encountered: