Open robsonfj opened 1 year ago
I copied your schema and pasted it into local file, use loadLocalSchema("scripts/local.graphql") to generate code
Cannot reproduce, it works
hmm, i'm using the GraphQLStateGenerator... could that be the diference? running here with AsyncGenerator works too... only with GraphQLStateGenerator that fails
const generator = new GraphQLStateGenerator({
schemaLoader: async () => {
const { typedefs } = await import('../server/src/graphql/schemas')
const schema = buildASTSchema(typedefs)
return schema
},
targetDir: path.join(typesPath, 'graphql'),
})
await generator.generate()
Yes, they are very different
After discovering the shortcomings of apollo client and facebook relay, I developed graphql-state. Graphql-state is actually a relational database in the browser, so it needs all object have ids. However, until now, graphql-state does not support the use of union types to express the inheritance relationship of objects with ids.
If you don't want to use graphql-state, no issue; if you want to use graphql-state, here's a work around (because I'm currently busy developing another project of mine: jimmer, I can't find time to implement this not simple function enhancement in the short term)
type Document {
id: ID!
sections: [Section!]!
}
interface Section {
id: ID!
}
type SectionDivider implements Section {
id: ID!
}
type SectionTitle implements Section {
id: ID!
text: String
}
type SectionParagraph implements Section {
id: ID!
text: String
}
Ah.. ok i'll use this workaround.... thanks 👍😁
Getting error when trying to generate types when the schema has union
Error: Section does not has id field \node_modules\graphql-ts-client-codegen\dist\state\GraphQLStateFetcherWriter.js:63:35 throw new Error(
${nodeType.name} does not has id field
);Schema