Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature req: add tooling that generates types from schema #107

Open
Birowsky opened this issue Aug 6, 2017 · 13 comments
Open

feature req: add tooling that generates types from schema #107

Birowsky opened this issue Aug 6, 2017 · 13 comments

Comments

@Birowsky
Copy link

Birowsky commented Aug 6, 2017

Have you checked any of these projects?

Is there one you are leaning towards?

@DxCx
Copy link
Owner

DxCx commented Aug 6, 2017

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 :)

@Birowsky
Copy link
Author

Birowsky commented Aug 6, 2017

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.

@Birowsky
Copy link
Author

Birowsky commented Aug 6, 2017

  • 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?

@DxCx
Copy link
Owner

DxCx commented Aug 6, 2017

hey @Birowsky
have you seen graphql-code-generator i've suggested?

@Birowsky
Copy link
Author

Birowsky commented Aug 6, 2017

Holy donkey! I hadn't noticed that you actually recommended a different package:} Trying it asap.

@Birowsky
Copy link
Author

Birowsky commented Aug 6, 2017

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;
}

@DxCx
Copy link
Owner

DxCx commented Aug 7, 2017

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

@Birowsky
Copy link
Author

Birowsky commented Aug 7, 2017

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)

@DxCx
Copy link
Owner

DxCx commented Aug 7, 2017

Gql file here is not a valid schema..

@Birowsky
Copy link
Author

Birowsky commented Aug 7, 2017

sorry, i guess i was in a rush. edited.

@nknapp
Copy link

nknapp commented Aug 7, 2017

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...

@Birowsky
Copy link
Author

Birowsky commented Aug 7, 2017

@nknapp just mentioned it here. Wrong arguments in the resolvers.

@DxCx
Copy link
Owner

DxCx commented Aug 8, 2017

@dotansimha can you please help @Birowsky integrating type generation into this example repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants