victorgarciaesgi / simple-graphql-to-typescript Goto Github PK
View Code? Open in Web Editor NEW๐ ๐ Simple Typescript interface generator from a GraphQL api schemas or URL
Home Page: https://sgts.netlify.com/
License: MIT License
๐ ๐ Simple Typescript interface generator from a GraphQL api schemas or URL
Home Page: https://sgts.netlify.com/
License: MIT License
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'
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?
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.
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
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:
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
.
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'
]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.