Skip to content
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

Port changes from graphql-js v0.5.0 (April 2016 spec) #123

Merged
merged 34 commits into from
Jun 11, 2016

Conversation

sogko
Copy link
Member

@sogko sogko commented Apr 18, 2016

Started work on porting changes from graphql-js v0.5.0 which is based on the latest April 2016 spec.

Previous port was based on v0.4.18 (pending PR #117 merge)


Notable changes:

  1. 58f2928 [RFC] Proposed change to directive location introspection
  2. 2322d25 [RFC] Directives in schema language
    • ❗️Breaking Changes: graphql.NewDirective(*graphql.Directive) => graphql.NewDirective(graphql.DirectiveConfig)
    • Affects those that defined custom directives.
  3. 03b92b0 Move getTypeOf to execute.js and rename to defaultResolveTypeFn to mirror defaultResolveFn
    • ❗️Breaking Changes: removed ObjectType(interface{}, ResolveInfo) *Object from Abstract interface, Union and Interface structs and moved to executor
    • Affects those that directly retrieved the ObjectType of an Abstract type (Union / Interface)
  4. 79f48da Add GraphQLSchema types field
    • ❗️Breaking Changes:
    • This introduces a breaking change to the Type System API. Now, any individual Interface type does not have the required information to answer GetPossibleTypes or IsPossibleType without knowing the other types in the Schema. These methods were moved to the Schema API, accepting the abstract type as the first parameter.
    • This also introduces a breaking change to the type comparator functions: IsTypeSubTypeOf and DoTypesOverlap which now require a Schema as a first argument.
  5. 1e33c35 [RFC] Add explicit context arg to graphql execution
    • ❗️Breaking Changes
    • Removed Schema from ResolveParams, already available in ResolveParams.Info
    • IsTypeOfFn and ResolveTypeFn params are now struct, similar to FieldResolveFn
    • context is now available for resolving types in IsTypeOfFn and ResolveTypeFn, similar to FieldResolveFn
  6. a241e1c RFC: Return type overlap validation
  7. e23ac77 Add Schema Definition to IDL.

Changes to public/exported vars / func

Previous New Risk
graphql.NewDirective(*graphql.Directive) graphql.NewDirective(graphql.DirectiveConfig) Low-Medium
graphql.Abstract.ObjectType(interface{}, ResolveInfo) *Object removed Low-Medium
graphql.Union.ObjectType(interface{}, ResolveInfo) *Object removed Low-Medium
graphql.Interface.ObjectType(interface{}, ResolveInfo) *Object removed Low-Medium
graphql.IsTypeOfFn(interface{}, ResolveInfo) graphql.IsTypeOfFn(IsTypeOfParams) High
graphql.ResolveTypeFn(interface{}, ResolveInfo) graphql.ResolveTypeFn(ResolveTypeParams) High
graphql.ResolveParams.Schema removed, already available in graphql.ResolveInfo Low-Medium

Commit:
b3a512787618cfbed20c9717daf2d69444bf7f33 [b3a5127]
Parents:
5ea2ff1e17
Author:
Tim Griesser <tgriesser10@gmail.com>
Date:
9 March 2016 at 10:02:07 A
@switchtrue
Copy link
Contributor

When is this and #117 likely to be merged in?

@bsr203
Copy link

bsr203 commented May 27, 2016

I was checking to see whether 0.6.0 would be supported :-)

there are breaking changes and first class support for context

https://gist.github.com/steveluscher/ffc1dfefbb10ad280c8a4c520a5c201c

Issue is relay is moving faster and not sure how it interop with this library with support for graphql v 0.6.0
https://github.com/facebook/relay/blob/master/CHANGELOG.md#090-may-26-2016

sogko added 9 commits May 30, 2016 11:14
This proposes a change to how we represent the ability to validate the locations of directives via introspection.

Specifically, this deprecates `onField`, `onFragment`, and `onOperation` in favor of `locations` which is a list of `__DirectiveLocation`.

**Rationale:**

This allows for a more fine-grained validation of directive placement, now you can assert that a directive is allowed on queries but not mutations, or allowed on fragment definitions but not on fragment spreads.

Also, this makes expanding the locations a directive is allowed to be placed easier to do, as future expansions will not affect the introspection API. This should be considered a prereq to graphql-go#265.

Finally, this is a prereq to a forthcoming RFC to add directives to the type schema language, one of the last missing pieces to represent a full schema using this language. Currently considering something like:

```
directive @Skip(if: Boolean) on FIELD, FRAGMENT_SPREAD, INLINE_FRAGMENT
```

**Drawbacks:**

Any change to the introspection API is a challenge. Especially so for graphql-js which is used as both client tools via Graph*i*QL and as a node.js server.

To account for this, I've left the existing fields as deprecated, and continued to support these deprecated fields in `buildClientSchema`, which is used by Graph*i*QL. While graphql-js will likely continue to expose these deprecated fields for some time to come, the spec itself should not include these fields if this change is reflected.

Commit:
e89c19d2ce584f924c2e0e472a61bb805ce260d4 [e89c19d]
Parents:
57d71e108a
Author:
Lee Byron <lee@leebyron.com>
Date:
18 March 2016 at 7:33:28 AM SGT
Commit Date:
18 March 2016 at 7:57:11 AM SGT
Labels:
HEAD
@sogko
Copy link
Member Author

sogko commented May 30, 2016

Hi @bsr203

Man, it was barely a month ago graphql-js 0.5.0 was released, now its 0.6.0, phew~ lol

Yeah I'll definitely try to bring up this library up to parity as quickly as possible when I get free time off work. First 0.5.0, then 0.6.0 😅

Re: breaking changes from 0.5.0 -> 0.6.0, it looks promising so far:

  • We already have support for context using net/x/context with PR Adds Context support. #98.
  • The position of info being changed due to addition of context does not apply for graphql-go, since we already passed all params for ResolveFn through ResolveParams struct.

Cheers!

sogko added 15 commits May 30, 2016 17:21
Add tests confirming graphql-go#319

Commit:
3278e861837cd3f7d17eaec54f3f04b175300826 [3278e86]
Parents:
3ce90faf26
Author:
Lee Byron <lee@leebyron.com>
Date:
23 March 2
This adds directives to schema language and to the utilities that use it (schema parser, and buildASTSchema). Directives are one of the few missing pieces from representing a full schema in the schema language.

Note: the schema language is still experimental, so there is no corresponding change to the spec yet.

DirectiveDefinition :
  - directive @ Name ArgumentsDefinition? on DirectiveLocations

DirectiveLocations :
  - Name
  - DirectiveLocations | Name

Example:

```
directive @Skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

directive @include(if: Boolean!)
  on FIELD
   | FRAGMENT_SPREAD
   | INLINE_FRAGMENT
```

Commit:
fdafe32724f2d6dac1ba360f1a440c0e633e75d9 [fdafe32]
Parents:
bf763b6f53
Author:
Lee Byron <lee@leebyron.com>
Date:
18 March 2016 at 10:47:06 AM SGT
Commit Date:
23 March 2016 at 6:19:46 AM SGT
graphql/graphql-spec#90

Commit:
b0885a038ec0e654962d69fb910ac86659279579 [b0885a0]
Parents:
fdafe32724
Author:
Lee Byron <lee@leebyron.com>
Date:
23 March 2016 at 6:35:37 AM SGT
Commit Date:
23 March 2016 at 6:35:39 AM SGT
This implements the schema definition in the spec proposal in graphql/graphql-spec#90

Adjusts AST, parser, printer, visitor, but also changes the API of buildASTSchema to require a schema definition instead of passing the type names into the function.

Commit:
8379e71f7011fe044574f4bdef2a761d18d6cf2c [8379e71]
Parents:
176076c8a6
Author:
Lee Byron <lee@leebyron.com>
Date:
23 March 2016 at 7:38:15 AM SGT
Labels:
HEAD
Commit:
533fc43f7d5836fc9b6a3eafde9801db9a3ee011 [533fc43]
Parents:
371a5a0908
Author:
Lee Byron <lee@leebyron.com>
Date:
23 March 2016 at 8:21:04 AM SGT
Commit Date:
23 March 2016 at 8:22:42 AM SGT
Commit:
43992e3a60d7bf8f5e7d2f29dfae302b5ba72eec [43992e3]
Parents:
533fc43f7d
Author:
Lee Byron <lee@leebyron.com>
Date:
23 March 2016 at 8:58:05 AM SGT
Commit:
43992e3a60d7bf8f5e7d2f29dfae302b5ba72eec [43992e3]
Parents:
533fc43f7d
Author:
Lee Byron <lee@leebyron.com>
Date:
23 March 2016 at 8:58:05 AM SGT
…rror defaultResolveFn

Commit:
edc405a11508a110759ce53c9efb2eb6dd2d181c [edc405a]
Parents:
3f6a7f4ca9
Author:
jeff@procata.com <jeff@procata.com>
Date:
24 March 2016 at 3:15:33 PM SGT
… coverage.

Should be removed once `onOperation`, `onFragment`, `onField` are dropped from spec.
This is a rebased and updated version of @tgriesser's graphql-go#199. I further extended it to completely remove the side-effectful mutation of Interface types rather than just deferring that mutation to schema creation time.

This introduces a *breaking* change to the Type System API. Now, any individual Interface type does not have the required information to answer `getPossibleTypes` or `isPossibleType` without knowing the other types in the Schema. These methods were moved to the Schema API, accepting the abstract type as the first parameter.

This also introduces a *breaking* change to the type comparator functions: `isTypeSubTypeOf` and `doTypesOverlap` which now require a Schema as a first argument.

Commit:
6a1f23e1f9c1e6bf4cea837bc9bb6eae0fb5c382 [6a1f23e]
Parents:
a781b556ee
Author:
Lee Byron <lee@leebyron.com>
Date:
23 March 2016 at 1:17:43 PM SGT
Commit Date:
25 March 2016 at 6:35:39 AM SGT
This **BREAKING** change introduces a new argument to the GraphQL execution API which is presented to resolution functions: `context`.

Removed `Schema` from `ResolveParams`, already available in `ResolveParams.Info`.

`IsTypeOf` and `ResolveType` params are now struct, similar to `FieldResolveFn`.

`context` is now available for resolving types in `IsTypeOf` and `ResolveType`, similar to `FieldResolveFn`.

Commit:
d7cc6f9aed462588291bc821238650c98ad53580 [d7cc6f9]
Parents:
576b6a15d1
Author:
Lee Byron <lee@leebyron.com>
Date:
23 March 2016 at 10:30:13 AM SGT
Commit Date:
25 March 2016 at 8:20:10 AM SGT
* Replace silent conversion to null with an invariant and a useful error message

Commit:
dea5aacca01f4429026bea3d97ea7cbc88b33bcf [dea5aac]
Parents:
39744381d5
Author:
Jeff Moore <jeff@procata.com>
Date:
5 April 2016 at 12:48:14 PM SGT
Committer:
Lee Byron <lee@leebyron.com>
sogko added 7 commits May 31, 2016 22:39
Commit:
d6da0bff7f877e6a4fb66119796809f9c207f841 [d6da0bf]
Parents:
136630f8fd
Author:
Dylan Thacker-Smith <dylan.smith@shopify.com>
Date:
5 April 2016 at 12:56:27 PM SGT
Committer:
Lee Byron <lee@leebyron.com>
Labels:
HEAD
Commit:
47f87fa701cb33fc1fb0ca65b4668c7a14a5ad11 [47f87fa]
Parents:
9e5d959353
Author:
Lee Byron <lee@leebyron.com>
Date:
5 April 2016 at 1:00:00 PM SGT

remove non spec compliant test

Commit:
07e627adda2b236e720ec352b21eb3043170c60f [07e627a]
Parents:
cf5b2340f9
Author:
Lee Byron <lee@leebyron.com>
Date:
5 April 2016 at 1:09:42 PM SGT
Commit:
3201ebb825f7bab4ca4856238ade4603e15a5abc [3201ebb]
Parents:
c7e6a75277
Author:
Lee Byron <lee@leebyron.com>
Date:
6 April 2016 at 11:08:06 AM SGT
Labels:
HEAD
- `completeValue` would already have resolved the value for `func() interface{}`
Implements graphql/graphql-spec#162

This alters the "Overlapping Fields Can Be Merged" validation rule to better express return type validation issues.

The existing rule has presented some false-positives in some schema where interfaces with co-variant types are commonly used. The "same return type" check doesn't remove any ambiguity.

Instead what that "same return type" check is attempting to prevent is spreading two fragments (or inline fragments) which have fields with return types where ambiguity would be introduced in the response.

In order to curb false-positives, we later changed this rule such that if two fields were known to never apply simultaneously, then we would skip the remainder of the rule.

```
{
  ... on Person {
    foo: fullName
  }

  ... on Pet {
    foo: petName
  }
}

```

However this can introduce false-negatives!

```
{
  ... on Person {
    foo: birthday {
      bar: year
    }
  }

  ... on Business {
    foo: location {
      bar: street
    }
  }
}

```

In the above example, `data.foo.bar` could be of type `Int` or type `String`, it's ambiguous!

This differing return type breaks some client model implementations (Fragment models) in addition to just being confusing.

Commit:
c034de91acce10d5c06d03bd332c6ebd45e2213c [c034de9]
Parents:
ffe76c51c4
Author:
Lee Byron <lee@leebyron.com>
Date:
7 April 2016 at 2:00:31 PM SGT
Labels:
HEAD
@sogko sogko added this to the 0.5.0 milestone May 31, 2016
@sogko sogko mentioned this pull request May 31, 2016
@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 90.754% when pulling 34413d2 on sogko:sogko/0.5.0 into a5cf5f2 on graphql-go:master.

@sogko sogko mentioned this pull request Jun 1, 2016
@sogko sogko changed the title [WIP] Port changes from graphql-js v0.5.0(April 2016 spec) Port changes from graphql-js v0.5.0 (April 2016 spec) Jun 1, 2016
@sogko
Copy link
Member Author

sogko commented Jun 1, 2016

Hi guys,

Calling for comments / reviews for this PR.
This will put graphql-go on par with graphql-js v0.5.0 and fully April 2016 spec compliant. (yay)

I know this is a huge dump of commits at the moment, because we are basically playing catch up to graphql-js (which just released 0.6.0 lol)

I've listed notable big changes in the original PR description, along with anything that introduces breaking changes to the API.

/cc: @chris-ramon @bsr203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants