-
Notifications
You must be signed in to change notification settings - Fork 2.1k
GraphQLObjectTypeConfig<TSource>
to GraphQLFieldResolveFn<TSource, TResult>
#425
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
Conversation
046cbba
to
e2dc75c
Compare
node_modules | ||
coverage | ||
dist | ||
.vscode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you remove this to keep this PR single-purpose?
Thanks for your hard work on this! I've left some comments inline, but please reduce the scope of this to only the changes necessary for this change - otherwise it's difficult to follow what was necessary and what was not |
2701c60
to
3de66da
Compare
src/__tests__/starWarsData.js
Outdated
@@ -1,10 +1,12 @@ | |||
/* @flow */ | |||
/* eslint quote-props: ["error", "as-needed", | |||
{ "keywords": true, "unnecessary": false }]*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to fix Flow error: non-string literal property keys not supported
, like:
const droidData = {
2000: threepio,
2001: artoo,
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for the explanation!
I think you actually want {numbers: true}
rather than keywords
to handle this case.
I just landed a change which applies this across the whole project so that we would not need this special case, so now it can be removed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its cool, will remove them.
Amended code style. |
Flow does not allow unquoted numeric object properties, so ensure ESLint and Flow agree on this. As originally illustrated in #425
description: 'The friends of the human, or an empty list if they ' + | ||
'have none.', | ||
resolve: human => getFriends(human), | ||
resolve: (human: Human): Array<Promise<Character>> => getFriends(human), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these resolve function type hints necessary? I would expect that Flow would not require them since you already typed getFriends
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is necessary, the input and output datatype should be a part of schema's design. A explicit declare give the resolver a constraint.(Makes it clear to other people, what data should be in and what data should be out).Will explain this below.
src/__tests__/starWarsSchema.js
Outdated
|
||
import { getFriends, getHero, getHuman, getDroid } from './starWarsData.js'; | ||
|
||
import type {Character, Human, Droid} from './starWarsData.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stylistic issue: please use spaces inside the { }
in import to match the others in the project
3de66da
to
784cd09
Compare
This cleans up the top level tests and flow-types them. It also moved one unrelated test into a more appropriate location. Inspired by #425
This cleans up the top level tests and flow-types them. It also moved one unrelated test into a more appropriate location. Inspired by #425
GraphQLObjectTypeConfig<TSource>
toGraphQLFieldResolveFn<TSource, TResult>
Make user can do a whole top-bottom Flow check between their resolvers.
With the Flow typed feature, user can ensure his data structure is correspond to schema . ex: starWarsData.js L103
More details see the src/tests/starWarsSchema.js
A simple demonstration:
Note: Because in v0.61 ,in source code use a
any
type to force castTSource
. So it is user's responsibility to check the Data Type is not typo. In above code , ifresolve: (src:DPost):DComment[]
is typo toresolve: (src:DPost):DSomeAnotherType[]
(and user return a wrong data), Flow will still pass. Flow will not checkDSomeAnotherType
isDComment
,cause ofDSomeAnotherType
->any
->DComment