joarwilk / gql2flow Goto Github PK
View Code? Open in Web Editor NEWConvert a GraphQL Schema to a flow definition
Convert a GraphQL Schema to a flow definition
I am not sure why it's happening. I am running the command gql2flow http://localhost:3000/graphql
inside my project folder where graphql
module installed. It should be able to find it yet fails...
Error: Cannot find module 'graphql/utilities'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (D:\users\DarkMaster\AppData\Roaming\nvm\v8.1.4\node_modules\gql2flow\util\fetcher.js:7:5)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
I am on Windows 10 x64, Node 8.1.4
First off, thanks for a great library! This is very useful.
Second, right now, I get a diff whenever I run gql2flow http://localhost:4000/api -o src/tools/types/schema/index.js.flow --null-keys
even though the GraphQL schema hasn't changed; this diff is just the gql2flow
output shuffling around in a different order:
It would be great if the output wouldn't change if the input didn't change so that there is no diff when there are no changes.
Lets say there's an input type:
input UpdateProfileInput {
id: ID!
name: string
email: string
}
The generated type is:
declare type UpdateProfileInput = {
id: string;
name: ?string;
email: ?string;
}
Which requires that both name and email be provided. This input object would falsely give an error:
const input = {
id: '123',
name: 'John Doe',
}
To get rid of the error right now you have to do:
const input = {
id: '123',
name: 'John Doe',
email: undefined
}
The generated type should be:
declare type UpdateProfileInput = {
id: string;
name?: ?string;
email?: ?string;
}
Using URL argument my input Types are all declared as {}
.
I'd like to use the generated Flow types in my resolvers. Resolvers do not return __typename
field; it is an internal field. Whats the reason for including it in the output?
See this comment: cfa8ced#commitcomment-22173728
Hi, the scheme generated with gql2flow looks like this:
export type Query = {
__typename: string;
/** Fetches an object given its ID */
node?: Node;
me?: User;
viewer?: Viewer;
}
but it should be
export type Query = {
__typename: string;
/** Fetches an object given its ID */
node: ?Node;
me: ?User;
viewer: ?Viewer;
}
Am I right? Because the key is always defined, but it can return null
It is not active at the moment https://travis-ci.org/joarwilk/gql2flow
Hi,
I'm using a graph.cool backend and there I have tons of types I would like to ignore. In my case it makes more sense to choose which types should be generated, not ignored. Any thought?
We want to be able to import types using import
, not have every type globally declared.
I would like to add gql2flow
step on this updateSchema
script, so when I generate a new schema.json
I would also generate a new .flow
file
https://github.com/entria/graphql-dataloader-boilerplate/blob/master/scripts/updateSchema.js
I woud like to do something like this:
import gql2flow from 'gql2flow`
gql2flow(`path/to/schema.json`, `output/path`);
I am not sure why Enum is appended to Enum type names. I would prefer to just use the names used in the schema.
FlowType allows 3 cases of optional fields and nullable types as explained here:
https://stackoverflow.com/questions/37165601/flowtype-how-to-annotate-union-with-optional-fields/37174244#37174244
When a user marks a GraphQL field as NonNull, the current code assumes the 3rd case, which is incorrect. It should assume the 2nd as the GraphQL spec does not allow the 3rd case.
https://github.com/joarwilk/gql2flow/blob/master/util/interface.js#L104
Hi, @joarwilk
Thanks for this lib!
I have a question.
How do you use file generated by this script ? Do you add it somewhere to .flowconfig so types would be global ?
I'm thinking to add export
before every type
keyword, so I could import them anywhere. May be this should be default behaviour?
Given this GraphQL type:
input PaginationInput {
first: Int = 20
last: Int
}
The following FlowType is generated:
declare type PaginationInput = {
first?: number;
last?: number;
}
But it should look like this:
declare type PaginationInput = {
first: number;
last?: number;
}
Hi! Will be nice to see such updates! What do you think?
Schema example
type Thing {
name: String!
}
input ThingsFilter {
nameStartFrom: String
}
type Query {
things(count: Number!, filter: ThingsFilter): [Thing!]
}
input ChangeProjectTitleInput {
name: !String
}
type Thing {
thing: Thing!
}
type Mutation {
addThing(input: AddThingInput!): AddThingPayload
}
Current output:
...
declare type Query = {
things: ?Array<Thing>;
}
declare type AddThingInput = {
name: string;
}
declare type AddThingPayload = {
thing: Thing;
}
declare type Mutation = {
addThing: ?AddThingPayload;
}
Expected output:
...
declare type ViewerSubjectsArgs = {
count: number;
filter: ?ThingsFilter;
}
declare type Query = {
things<ViewerSubjectsArgs>(): ?Array<Thing> | Promise<?Array<Thing>>;
}
declare type AddThingInput = {
name: string;
}
declare type MutationAddThingArgs = {
input: AddThingInput;
}
declare type AddThingPayload = {
thing: Thing;
}
declare type Mutation = {
addThing<MutationAddThingArgs>(): ?AddThingPayload | Promise<?AddThingPayload>;
}
It is really hard to contribute to a repository when the tests are broken. :-(
I have this GraphQLEnumType
export default new GraphQLEnumType({
name: 'BirthdayFilter',
values: {
day: {
value: 'day',
description: 'people doing birthday today',
},
week: {
value: 'week',
description: 'people doing birthday in this week',
},
month: {
value: 'month',
description: 'people doing birthday in this month',
},
},
});
and it is generating this:
null
export type BirthdayFilter = "day" | "week" | "month";
All our Date
types end up as any
.
Hey...
this repo looks pretty familiar. just wanted to let you know that the v1 of gql2ts supports flow output (and would appreciate any help to improve that) and fixes a bunch of issues with the v0.x versions (which this seems to be based off of)
p.s. in the future, forking, attributing, or maintaining the history would really be nice. i understand that our license is MIT and I have no leg to stand on, but some attribution would go a long way.
now I have to make the IntrospectionQuery
myself, save the file as json and then run gql2flow command.
It would be really convenient if I could just do something like:
gql2flow https://graphql-explorer.githubapp.com/graphql/proxy
It has been quite a while since the last release, there are still bugs in the latest published 0.4.5
As far as I know this is still the best GraphQL -> FlowType tool out there. Would you like help maintaining this project?
most types are generated as these two:
description: ?string;
target: ?any;
wouldn't it make more sense to generate them rather as:
description?: string;
target?: any;
Since we're always "picking" props we're expecting from the backend in graphql?
If an interface description is set to null
https://github.com/joarwilk/gql2flow/blob/master/util/interface.js#L37
will output the literal string null
since it's returned inside the string literal.
Would be great if this supported schema.graphql
file types as well so it could be used with graphql-cli
: https://github.com/graphcool/graphql-cli.
"The format specified by graphql-config will be the foundation for all schema-aware GraphQL tools...If you're the author or maintainer of a GraphQL library or another related tool, we encourage you to adopt the graphql-config standard. Please link to this GitHub issue to track the progress.
As mentioned before, the graphql-cli can be extended with plugins to support custom use cases. Feel free to start building your own plugins to support your GraphQL development workflow or tackle further use cases."
https://www.graph.cool/blog/2017-08-01-graphql-config-and-cli-aeghee3di9/
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.