feature req: add tooling that generates types from schema
Have you checked any of these projects?
- Apollo GraphQL code generator: https://github.com/apollographql/apollo-codegen
- GQL2TS: https://github.com/avantcredit/gql2ts
- GraphQL To Typescript: https://github.com/3VLINC/graphql-to-typescript
- graphql-typewriter: https://github.com/nknapp/graphql-typewriter
Is there one you are leaning towards?
Hey @Birowsky
The generator ive liked the most is https://github.com/dotansimha/graphql-code-generator But i have a task of making webpack plugin that will capture all required .gql files and add one virtual model for it.. If you want to integrate it as build step in the meanwhile you are welcome :)
Hey mister!
I couldn't figure out how to do .json -> .d.ts with apollo-codegen. They only document how to accomplish that for clients.
The types output file is empty: https://stackoverflow.com/q/45534529/592641
With graphql-typewriter however, all I do is: graphql-typewriter. No joke. The interfaces module is created right there next to the .graphqls file. I later discovered that the graphql version it produces types for, is old. So they don't match.
- GQL2TS types are scarse
- graphql-typewriter is great, but two graphql versions behind, so types are wrong.
- GraphQL To Typescript is one version behind and throws weird error
What step would you next take?
hey @Birowsky have you seen graphql-code-generator i've suggested?
Holy donkey! I hadn't noticed that you actually recommended a different package:} Trying it asap.
Sad news. For this schema:
schema { query: Query }
type Query { onion(peal:String!):Float }
I got these types:
export interface Query {
onion: number | null;
}
export interface User {
id: string | null;
email: string | null;
}
Hey @Birowsky, Can you open a branch with that? I wanna take a look since i do have good experiance with that in the past
We don't need a branch for that. This is the schema.graphqls file:
schema {
query: Query
}
type Query {
someQuery(inputArg:String):Float
}
these are the commands that I run on it:
apollo-codegen introspect-schema schema.graphqls --output schema.json
gql-gen --file schema.json --template typescript --out schema.d.ts
here's the resulting schema.d.ts:
export interface Query {
someQuery: number | null;
}
export interface SomeQueryQueryArgs {
inputArg: string | null;
}
on the other hand, here's what graphql-typewriter gives us:
/* tslint:disable */
export namespace schema {
export type GraphqlField<Args, Result, Ctx> = Result | Promise<Result> |
((args: Args, context: Ctx) => Result | Promise<Result>)
export interface Query<Ctx> {
someQuery?: GraphqlField<{inputArg: string}, number | undefined, Ctx>
}
export const defaultResolvers = {
}
}
the types are way more complete, but they are incorrect (probably because the tool is old)
Gql file here is not a valid schema..
sorry, i guess i was in a rush. edited.
Could you open an issue with the exact errors in graphql-typewriter? We'd need to know what exactly is wrong.
Although the project has not had an update for a while, it is not abandoned...
@nknapp just mentioned it here. Wrong arguments in the resolvers.
@dotansimha can you please help @Birowsky integrating type generation into this example repo?