-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Export flow types from index.js #554
Conversation
Note: this contains a breaking change! Within field resolvers, |
This adds all flow types exported from individual files to relevant index.js files as well. This enables those using graphql.js with flow to write something like: ```js import type { ... } from 'graphql' ```
b1d3a19
to
e49df49
Compare
According to breaking change in graphql/graphql-js#554
Test 0.8.0-beta1 in our project. |
This seems like a bad idea to me. A lot of these Flow types do not seem to be set up in a way that makes them usable outside of this library. Consider As such, it's quite inconvenient to get any sort of type checking with GraphQL schemas that use Flow – essentially it'd require large amounts of coercion to and from I would strongly recommend backing out the update to include the Flow types. As set up right now, I don't see a good way to make use of these typings. I don't think there's a trivial fix available either – it looks like it's going to take some effort to rethink the typings in such a way that they work well for users of this library. |
:/ I would really hope for this kind of feedback during the beta phase, it's too late to back out of this release. At this point I'm open to ideas on how to make the typings more useful going forward. Should we type some more complex things as |
I don't think removing Flow annotations is semver-breaking. They shouldn't cause any additional errors for users of this library. Short of typing everything as
But I really don't know. I wasn't able to update my GraphQL schema because I have a dependency on |
Thanks for the feedback. It sounds like there are two categories of users of types with different needs. One group is looking for types to make guarantees about their usage of the functions exported by GraphQL.js, others are looking for types to make guarantees about their resolver functions being correct. The former seems happy with the change, the latter seems unhappy. Removing types completely will make the former group unhappy. So I think the right thing to do now is just to add |
Though in a perfect world – and this might even be possible with I think regardless there's a lot of thought that's going to be necessary to expose type definitions that would be useful for defining schemas – enough to be a fairly significant project. They're not necessarily going to be the same kind of type definitions that would be useful for this package internally. They're somewhat difficult even for other libraries that consume this library. |
I feel like the actual final solution probably involves some code generation to either create the schema argument types from the flow types, or the other way around. |
I think the issue is that if you type e.g. the I don't see how you can just use the functions exported by GraphQL.js unless you are doing so entirely outside of the context of defining a schema. The idea of applying a minimal type check to calls to I don't think the tradeoff of having type checks for calls to |
It's like actual C++ template stuff. I wish it were documented. |
That was the current state of things before adding Flow types. So my point here is that rather than removing them all-together we can just weaken them where they're insufficient. Adding back typings later can be considered breaking changes.
Exactly this. It's not an uncommon use case, especially if you're building other libraries for doing things with GraphQL. |
Sorry, what I mean specifically is that loosening up the typings reduces the type-safety of code within this library. As a consumer of this library, I'd rather not be exposed to potential type safety errors within the graphql-js library that might arise from re-typing things from Also, the use case for those libraries only applies to ones that are entirely agnostic to the underlying schema. This doesn't even apply for cases like graphql-relay-js that expose field definition helpers like https://github.com/graphql/graphql-relay-js/blob/v0.4.3/src/node/plural.js#L50-L55. |
That's not quite true. It applies to those libraries which are just not defining the resolver functions for underlying schema. Libraries that use a schema still benefit from this kind of typing and was the primary motivator for adding them. |
Please correct me if I'm off-base here, but I'm understanding your feedback to be specific to the type safety of field resolver functions, is that correct? |
That's the first example that came to mind. I was taking a stab at updating graphql-relay-js, but stopped when I realized that making the Regarding libraries that use schemas – would it be possible to just stop exporting the typings for schema type definitions, and only retain those exports that are useful for those use cases? e.g. export the signature for |
At some point you need to bridge between the typed and untyped worlds. That would mean exporting a signature for That means at some-point, somewhere, there will be a cast through I'm not sure if removing flow types for GraphQLObjectType is the answer here since that may create inconsistencies. I'll start by looking into improving the resolver methods and then removing the need for casting through any as much as possible while retaining as much strong typing as we can. I think that definitely means that there will be opportunity to improve the type safety of field resolver functions over time, and those likely will require breaking change version bumps - but at least we can start from a place where we have some typing. |
Fair enough – in practice I can't really imagine any bugs that could potentially arise in graphql-js from typing e.g. |
Certainly no new kinds of bugs that we wouldn't have seen in a version before Flow types at all. I can also work with the Flow team in coming up with ways to more correctly type what we have. |
This adds additional type information to field resolvers, such that source and context get slightly more appropriate types. This partially improves one of the issues raised in #554
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.
Review
This adds all flow types exported from individual files to relevant index.js files as well.
This enables those using graphql.js with flow to write something like: