Giter VIP home page Giter VIP logo

simple-graphql-to-typescript's Introduction

simple-graphql-to-typescript's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar j-hassani avatar victorgarciaesgi avatar victortotem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

c8r821

simple-graphql-to-typescript's Issues

ReferenceError: sgtsQL is not defined

Hi :D

So one last thing: What's the thing about sgtsQL, because I can't find anything about it in the docs.
Since I also use the generated types in some backend-related code, I get ReferenceError: sgtsQL is not defined because there is no import for that function in the generated types file.

Is there some way to omit fragement generation?

Return type of vue-hooks

First things first: this project looks amazing and I am super excited to use it!

I have a question though and was hoping you could provide some clarification. It looks like the wrong type is being passed into the useQuery call. If right now I have a User model in my graphql schema the code generated will be

useQuery<UseQueryOptions<{ users: User[] }, usersArgs>>(query, variables, options);

But according to the code generated by the react-hooks generator and from what I can tell from the vue-apollo documentation it should be

useQuery<{ users: User[] }, usersArgs>(query, variables, options);

This means that if I try to use the useUsers hook the returned result has the wrong type but the correct contents.

Thanks,
Carter

Cannot find module 'inquirer'

Error: Cannot find module 'inquirer'
Require stack:
- /Users/abhishiv/work/gratico/gratico/node_modules/simple-graphql-to-typescript/dist/rc/index.js
- /Users/abhishiv/work/gratico/gratico/node_modules/simple-graphql-to-typescript/dist/sgts-bin.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/abhishiv/work/gratico/gratico/node_modules/simple-graphql-to-typescript/dist/rc/index.js:10:36)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/abhishiv/work/gratico/gratico/node_modules/simple-graphql-to-typescript/dist/rc/index.js',
    '/Users/abhishiv/work/gratico/gratico/node_modules/simple-graphql-to-typescript/dist/sgts-bin.js'
  ]

Will crash if there is no .prettierrc fille

Will get stuck after it fails to load the (missing) .prettierrc:

sgts -e http://localhost:3000/graphql -o api.ts -G -A
Running Prettier with your config on the generated output
Error: Cannot find module '../../.prettierrc'

Support Union Types

First of all, thank you for this great tool! It addresses and solves the exact problems which have prevented me from using other graphql code generators. Great work!

Are there any plans to support union types? Running sgts on my GraphQL endpoint exposing one union type ends in a not-compilable ts file because the type definition for the union type is missing.

GraphQL Schema:

type FileUpload {
  container: String!
  blob: String!
  fileExtension: String!
  originalFilename: String!
  hash: String!
  accessUrl: String!
}

union FileSource = FileUpload // more to come in the near future

The resulting ts file holds an interface for FileUpload and also uses the FileSource type for properties where it's referenced in the GraphQL schema, but there is no type definition for the FileSource type.

Custom scalars treats as undefined

Hi Victor, it seems like the --customScalars option didn't work correctly. I've been running sgts like

sgts --endpoint http://localhost:8080/graphql --output src/javascripts/shared/model/generated.ts --suffix Model --customScalars [{ "ObjectIdType": "ObjectIdType" }]

Finally in the output file I have found that all fields with ObjectIdType treats as undefined.

Nullable properties are optional at the same time

Hi, it's me again, still enjoying your library :)

I just stumbled upon the following thing:
For fields in the graphql schema which are marked as nullable, it generates the interface properties in the following way: someField?: Maybe<string>
Thus, the property value can be either a string, undefined, or null. But from my understanding, graphql doesn't know undefined, just null. So if I query a field which value is not set, I receive null.
The only scenario where an optional interface property would make sense are types which are used in mutation or query arguments, because there an optional field can be omitted.

So in the end, this results in the following questions:

  1. Is there any reasoning or necessary to mark nullable fields also as optional in typescript?
  2. Would it be possible to distinguish between types used as arguments and types which are returned by queries/mutations?
  3. Would it be possible (maybe via a cli flag) to omit the "optional", or would this break too much code on your side which rely on these optional properties?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.