-
Notifications
You must be signed in to change notification settings - Fork 0
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
Directive for Oneof Objects and Oneof Input Objects #1
base: main
Are you sure you want to change the base?
Conversation
expect(schema.getDirective('skip')).to.not.equal(undefined); | ||
expect(schema.getDirective('include')).to.not.equal(undefined); | ||
expect(schema.getDirective('deprecated')).to.not.equal(undefined); | ||
expect(schema.getDirective('specifiedBy')).to.not.equal(undefined); | ||
expect(schema.getDirective('include')).to.not.equal(undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be oneOf
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops yeah. Thanks!
src/type/directives.ts
Outdated
new GraphQLDirective({ | ||
name: 'oneOf', | ||
description: 'Indicates an Object is a Oneof Object or an Input Object is a Oneof Input Object.', | ||
locations: [DirectiveLocation.OBJECT, DirectiveLocation.INPUT_OBJECT], | ||
args: {}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new GraphQLDirective({ | |
name: 'oneOf', | |
description: 'Indicates an Object is a Oneof Object or an Input Object is a Oneof Input Object.', | |
locations: [DirectiveLocation.OBJECT, DirectiveLocation.INPUT_OBJECT], | |
args: {}, | |
}); | |
new GraphQLDirective({ | |
name: 'oneOf', | |
description: 'Indicates an Object is a Oneof Object or an Input Object is a Oneof Input Object.', | |
locations: [DirectiveLocation.OBJECT, DirectiveLocation.INPUT_OBJECT], | |
args: {}, | |
}); |
src/type/validate.ts
Outdated
if (isObjectType(type) && type.isOneOf) { | ||
validateOneofObjectField(type, field, context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the "of" sometimes gets capitalized (e.g. isOneOf
) and sometimes doesn't (e.g. validateOneofObjectField
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validateOneOfObjectField
probably make more sense, but I was confused myself what the capitalization should be. In the RFC they are called "Oneof Input Objects" but maybe that is just the titleized version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He also just writes "oneof" with no caps at all in a comment or two, so I'm not sure there's much consistency to be had ¯\_(ツ)_/¯
Either way it's probably not a big deal, I just happened to notice as I was reading through
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great (although I don't know much about graphql-js internals)! A few questions:
- Can
oneOf
be applied to interfaces since this is prototyping support in both inputs and outputs? - Can
oneOf
be applied to type extensions? Is there additional validation required either way? - This is intentionally not implementing one fields as described here right?
This adds the @OneOf directive as a default directive to indicate Objects and Input Objects as Oneof Objects/Input Objects which ensure there is exactly one non-null entry. Future commits will work to implement this directive.
This exposes a new boolean `oneOf` field on `__Type` that indicates if a type is `oneOf`. We implement by checking if the AST node for the object contains a `@oneOf` directive.
This validates that all fields of oneof objects are nullable and that all fields of oneof input object are nullable and do not have a default value.
80262f5
to
a9c4479
Compare
I imagine it would support interfaces. I'll have to come back to that.
The spec talks about how they apply to extensions here https://github.com/graphql/graphql-spec/pull/825/files#diff-30a69c5a5eded8e1aea52e53dad1181e6ec8f549ca2c50570b035153e2de1c43R1712-R1715 so I'll have to come back and make sure I've captured that part of the spec.
That's correct, Benjie seemed more concerned with getting objects and input objects implemented:
|
This adds `oneof` as a valid word so `Oneof` isn't flagged as a typo. I wasn't sure what the correct capitalization should be since the RFC styles it as "Oneof Input Objects" but in the schema it is `__Type.oneOf`. I tried to use "Oneof" in prose and `oneOf` in code.
I've only looked at this in GitHub (not checked it out and tried it/etc) but it looks good to me 👍 Capitalisation of |
That makes sense. Do would you imagine that we style it as
or
|
I think OneOf for consistency. |
I've opened this as a PR on the upstream repository graphql#3513 |
This sets the groundwork for an implementation of graphql/graphql-spec#825 for Objects and Input Objects (Oneof Fields omitted for now) by adding
@oneOf
as a built-in directive and exposing__Type.oneOf
during schema introspection.