Hey guys, thanks for your amazing project.
I would like to know if there is any plugin for that generates typeDefs like:
export const typeDefs = gql`
extend type Query {
isLoggedIn: Boolean!
cartItems: [ID!]!
}
extend type Launch {
isInCart: Boolean!
}
extend type Mutation {
addOrRemoveFromCart(id: ID!): [ID!]!
}
`;
I am using Apollo Local state management, therefore I want to generate the typeDefs automatically.
Thanks!
I had basically the same question.
My codegen yml looks like:
overwrite: true
schema: "./graphql/schema.graphql"
..
It would be useful to generate the typeDefs automatically based on this.
I used a custom plugin like:
typescript-typedefs.js:
const { printSchema } = require('graphql');
module.exports = {
plugin: (schema, documents, config) => {
return [
'import gql from "graphql-tag";',
'',
'export const typeDefs = gql`',
printSchema(schema),
'`;',
'',
].join('\n');
},
};
and then added the custom plugin in my codegen.yml:
overwrite: true
schema: "./graphqls/*.graphqls"
documents: null
generates:
src/generated/graphql.ts:
plugins:
- "typescript"
- "typescript-resolvers"
- "typescript-typedefs.js"
Maybe useful to add something like this to graphql-code-generator so other people can use out of the box?
Closing, as @marceloverdijk suggested a quick plugin implementation if someone needs that. Feel free to create a PR!
Most helpful comment
I used a custom plugin like:
typescript-typedefs.js:and then added the custom plugin in my codegen.yml:
Maybe useful to add something like this to
graphql-code-generatorso other people can use out of the box?