npm install flow-graphqlAdd flow-type outputs for Graphql
GraphQLObjectTypeConfig to GraphQLFieldResolveFnMore details see the src/__tests__/starWarsSchema.js
A simple demonstration:
``
type DCPost;
type DComment;
type DUser;
const Post = new GraphQLObjectType({
name: 'Post',
fields: () => ({
...
comment: {
type: new GraphQLList(Comment),
resolve: (src:DPost):DComment[] => { // Flow check DPost -> DComment[]
return ...;
} }
}),
});
const Comment = new GraphQLObjectType({
name: 'Comment',
fields: () => ({
...
user: {
type: User,
resolve: (src:DComment):DUser => { // DComment -> DUser
return ...;
}
},
}),
});
const User = new GraphQLObjectType({
...
});
`
Note: Because in v0.61 ,in source code use a any type to force cast TSource. So it is user's responsibility to check the Data Type is not typo. In above code , if resolve: (src:DPost):DComment is typo to resolve: (src:DPost):DSomeAnotherType[] (and user return a wrong data), Flow will still pass. Flow will not check DSomeAnotherType is DComment,cause of DSomeAnotherType -> any -> DComment
type printStyle = 'alphabet' | 'hierarchy';
export function printSchema(
schema: GraphQLSchema,style: printStyle = 'alphabet'): string {
switch (style) {
case 'hierarchy':
return printFineSchema(schema, n => !isSpecDirective(n));
case 'alphabet':
default:
return printFilteredSchema(schema, n => !isSpecDirective(n),
isDefinedType);
}
}
``