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

Added flag for mergeTypes to merge all types #118

Merged
merged 6 commits into from
Feb 25, 2018
Merged

Added flag for mergeTypes to merge all types #118

merged 6 commits into from
Feb 25, 2018

Conversation

squidfunk
Copy link
Contributor

This PR adds the ability to merge custom types, as demanded here. Precisely, it adds an option to mergeTypes, so the behavior is entirely downward compatible. Tests are also included. Now we can do the following:

# a.gql
type Custom {
  id: ID!
}

# b.gql
type Custom {
  name: String
  age: Int
}

Merge types with:

mergeTypes(types, { all: true })

Result:

type Custom {
  id: ID!
  name: String
  age: Int
}

@RichardLitt RichardLitt added the 🚀enhancement New feature or request label Feb 1, 2018
Copy link
Contributor

@cfnelson cfnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@squidfunk Thank you for the PR! It's appreciated a lot & thank you for including a test. 🔥 I have pulled down the branch and tested locally.

We would like to accept this PR but a few additional features & tests will need to be added before we will be comfortable accepting.

Two scenarios I noticed that were missing from the tests was when two or more Type Definitions had the same Field Definitions. e.g -> age field exists in both Types. The 2nd scenario is when the field definitions have differing type values.

export default `
  type Person {
    id: ID!
    name: String
    age: Float
  }
  type Person {
    name: String
    age: Int
  }
`;

Based on your modifications the output of the above would be:

"schema { query: Query } type Person { id: ID! name: String age: Float name: String age: Int }"

At minimum we would need to have additional tests created for the above scenarios and have them pass.

Suggestions for this:

For Scenario 1: name - we would expect name to only occur once in the Person type.

For Scenario 2: age - An acceptable first step would be to throw an Error and report where the conflicting field definitions are occurring to prompt the pkg user to resolve these conflicts in their type definitions.

There are some additional ideas/improvements that could be made and would be happy to collaborate/assist in improving this PR so that we can merge and accept it into master.

@squidfunk
Copy link
Contributor Author

Thank you for the PR review. I will take a look and try to handle the two cases you discussed, but I may need some assistance/directions. I will keep you updated when I make progress.

@cfnelson
Copy link
Contributor

cfnelson commented Feb 2, 2018

@squidfunk No worries, will be happy to collaborate further to improve the PR and get it accepted. Having a working naive solution as a basis to work off would be a good starting point. We would want to have multiple tests to cover any other scenarios that we have yet to discuss as well.

@squidfunk
Copy link
Contributor Author

Currently the problem with non-disjoint types (one field occurs in both type definitions) also applies to the mergeable type definitions (queries, mutations, subscriptions):

type Query {
  foo: Int
  bar: String
}
type Query {
  foo: String
  baz: Boolean
}

Results in:

schema {
  query: Query
}

type Query {
  foo: Int
  bar: String
  foo: String
  baz: Boolean
}

Therefore, in my opinion, it's not exclusively related to this PR. However, I will try to fix that too.

@squidfunk
Copy link
Contributor Author

squidfunk commented Feb 5, 2018

I covered the cases you specified in new test cases for custom types and for query types and seem to have fixed the stated issues. One issue remains: The arguments for fields (methods) of query types and custom types need to be checked prior to merging. However, this is also broken in the latest version and I would favor to do it in a separate PR (me or somebody else).

Any feedback is appreciated.

@squidfunk
Copy link
Contributor Author

Fixed one more error for comment nodes

@cfnelson
Copy link
Contributor

cfnelson commented Feb 5, 2018

@squidfunk Thanks for the updates 🔥 . @RodMachado and myself will review and test these new updates hopefully sometime this week.

Did you have any opinions/thoughts on how to approach the argument fields issue? Attempt to resolve or throwing an error?

@squidfunk
Copy link
Contributor Author

Did you have any opinions/thoughts on how to approach the argument fields issue? Attempt to resolve or throwing an error?

I would do it exactly as with the field types - if the definitions match, just merge them, otherwise throw an error. We also have to check arity and input types, but I think this should be done in a separate PR.

@cfnelson cfnelson requested a review from mohebifar February 16, 2018 18:14
Copy link
Contributor

@mohebifar mohebifar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 🚀 Definitely agree with throwing errors in case of conflicting fields and skipping the matching ones.

@kohlikohl
Copy link

What is the status of this PR?
Looks awesome and is exactly the addition to the library I am waiting for.
Anything I can do to help get this merged in?

@cfnelson
Copy link
Contributor

@kohlikohl It's ready to go! Waiting for final review, though we shouldn't hold this up any longer. We just need to update the README & CHANGELOG. After this is merged we can bump the pkg versions and publish to npm.

Any help with the above would be appreciated otherwise I will try to get it out in the next 24hrs.

@peterclemenko
Copy link

This is going to be awesome

@cfnelson
Copy link
Contributor

@RodMachado Been waiting for your review. Planning to merge without it now.

@cfnelson cfnelson merged commit 6480c67 into Urigo:master Feb 25, 2018
@cfnelson cfnelson mentioned this pull request Feb 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants