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

Extend the extend functionality #1095

Closed
kbrandwijk opened this issue Nov 20, 2017 · 7 comments
Closed

Extend the extend functionality #1095

kbrandwijk opened this issue Nov 20, 2017 · 7 comments

Comments

@kbrandwijk
Copy link

Currently, it's only possible to extend object types by spec. However, when using schema stitching, I'm running into use case where it would be nice to be able to extend other parts of my schema, like unions, interfaces, enums and input types.

I would like to be able to use the same syntax as for object types. For interfaces, enums and input types, I don't see any issues with that. For unions, the syntax is a bit different, so I'm open to suggestions for how that might look. As an alternative, the use case for unions might also be dealt with when merging schemas. If you agree with that, I will open an issue on graphql-tools for that. But for interfaces, enums, and input types, I think the change should be on the graphql-js side.

Examples:

extend enum MyEnum {
  NewValue
}

extend interface MyInterface {
  NewField: String
}

extend input MyInput {
  NewField: String
}
@leebyron
Copy link
Contributor

leebyron commented Jan 8, 2018

Syntax for this exists, however extendSchema needs additional logic for these cases. This would be a great task for someone to pick up who seeks to learn about this library

@grenierdev
Copy link

I've began the work to add the logic to extendSchema to support enum, input and interface extension.

I'm preparing a pull request with my changes. Is there any guidelines on how to submit a PR or I just have to refer to the contribution.md?

@IvanGoncharov
Copy link
Member

IvanGoncharov commented Apr 22, 2018

I've began the work to add the logic to extendSchema to support enum, input and interface extension.

@mgrenier Great 👍 You can submit WIP PR and get some early feedback.
Also, don't forget to test for tricky use cases like this:

extend input User {
  friends: [User]
}

@IvanGoncharov
Copy link
Member

Implemented by @mgrenier and merged as #1373 🎉
Available in 14.0.0-rc.1 📦

@dandv
Copy link

dandv commented May 19, 2019

Thanks for implementing this. Is passing the extended input fields supported?
The following example fails with:

GraphQLError: "password" is not defined

const { graphql, buildSchema } = require('graphql');

const schema = buildSchema(`
  input User {
    username: String!
  }
  extend input User {
    password: String!
  }
  type Query {
    hello: String
  }
  type Mutation {
    createUser(user: User): Boolean
  }
`);

var root = { createUser: user => console.log(user) };

graphql(schema, `mutation {
  createUser(user: {
    username: "john"
    password: "secret"
  })
}`, root).then((response) => {
  console.log(response);
});

@csantos1113
Copy link

Is there any news on this?

@IvanGoncharov
Copy link
Member

Thanks for implementing this. Is passing the extended input fields supported?

@dandv @csantos1113 Currently buildSchema doesn't support extensions, please see #922
I'm working on implementing this behavior in 15.0.0 and I will try to include it 15.0.0-alpha.0.

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

No branches or pull requests

6 participants