Graphql-js: Extend the extend functionality

Created on 20 Nov 2017  路  7Comments  路  Source: graphql/graphql-js

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
}
enhancement help wanted

Most helpful comment

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

All 7 comments

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

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?

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]
}

Implemented by @mgrenier and merged as #1373 馃帀
Available in 14.0.0-rc.1 馃摝

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);
});

Is there any news on this?

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.

Was this page helpful?
0 / 5 - 0 ratings