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

WrapType for mutations #1708

Closed
tommy5dollar opened this issue Jun 30, 2020 · 6 comments
Closed

WrapType for mutations #1708

tommy5dollar opened this issue Jun 30, 2020 · 6 comments
Labels
feature New addition or enhancement to existing solutions

Comments

@tommy5dollar
Copy link
Contributor

Hello,

We currently use graphql-weaver in our projects to merge together multiple GraphQL schemas into a single schema but are looking to migrate away, primarily as graphql-weaver only supports GraphQL 14.

It seemed like WrapType could be able to easily replace the functionality we were getting from graphql-weaver and it seems to do just that for queries but I also noticed that WrapType doesn't work for mutations.

Is there a technical reason why WrapType can't support mutations? Does anyone have any recommendations for how to achieve an equivalent to what we were previously getting from graphql-weaver? I'm currently stuck in a situation where I'll need to change the structure of our schema as it doesn't seem like the same schema can be achieved with GraphQL 15.

Thanks in advance.

@yaacovCR
Copy link
Collaborator

Does it not work? I think I wouldn't recommend it because of confusion to me about how exactly the contract of serial execution for mutation fields work.

But other than that, I don't think there are technical issues,

Subscriptions would have technical issues, as async iterators returned for root subscription fields, not for subfields, but mutations should work, just perhaps with some technical gotchas.

Could you open a PR with a failing test?

@tommy5dollar
Copy link
Contributor Author

Thanks for the swift response. I read in a couple of places that it wouldn't work but good to hear that there might not actually be a technical reason for it to not work. I was encountering issues but our stack has so much going on that it's very difficult to isolate the precise issue.

I'll try and put together something simple soon to test it out and will raise a PR if it fails. Thanks again!

@tommy5dollar
Copy link
Contributor Author

I've raised a PR with a failing test.

Let me know if I've done anything particularly stupid, or if there's anything I can do to help.

@yaacovCR yaacovCR added the waiting-for-release Fixed/resolved, and waiting for the next stable release label Jul 2, 2020
@yaacovCR
Copy link
Collaborator

yaacovCR commented Jul 2, 2020

Looks like I did something stupid, now reverted by #1723.

The latest changes of this PR are available as alpha in npm: 6.0.13-alpha-fa3c0f4.0

Quickly update your package.json by running:

npx match-version @graphql-tools 6.0.13-alpha-fa3c0f4.0

@tommy5dollar
Copy link
Contributor Author

Everything is working great now, thanks for all the help!

@tommy5dollar
Copy link
Contributor Author

Not directly relevant but seems easier to cover this in the same thread, especially since it seems WrapType related.

I'm encountering an issue where 2 resolvers have the same name but return data of types with different names, despite the resolvers being in different schemas and being WrapType'd into different namespaces.

The error is: Field "test" already defined with a different type. Declared as "Test1Response", but you tried to override with "Test2Response".

I'm happy to create a failing test again but thought I'd check first that this should be expected to work.

Below is some very basic code to recreate the issue:

const typeDefGen = i => `
type Query {
  test: Test${i}Response
}

type Test${i}Response {
  a: String!
}
`

const resolverGen = i => ({
  Query: {
    [`test`]: () => ({
      a: `test${i}Result`
    })
  }
})

const subschemaGen = i => ({
  schema: makeExecutableSchema({
    typeDefs: typeDefGen(i),
    resolvers: resolverGen(i)
  }),
  transforms: [new WrapType(`Query`, `test${i}_Query`, `test${i}`)]
})

const combinedSchema = stitchSchemas({
  subschemas: [subschemaGen(1), subschemaGen(2)]
})

@yaacovCR yaacovCR added feature New addition or enhancement to existing solutions and removed waiting-for-release Fixed/resolved, and waiting for the next stable release labels Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New addition or enhancement to existing solutions
Projects
None yet
Development

No branches or pull requests

3 participants