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

RFC: Schema Language Directives #376

Merged
merged 1 commit into from
May 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/language/__tests__/schema-kitchen-sink.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,52 @@ type Foo implements Bar {
six(argument: InputType = {key: "value"}): Type
}

type AnnotatedObject @onObject(arg: "value") {
annotatedField(arg: Type = "default" @onArg): Type @onField
}

interface Bar {
one: Type
four(argument: String = "string"): String
}

interface AnnotatedInterface @onInterface {
annotatedField(arg: Type @onArg): Type @onField
}

union Feed = Story | Article | Advert

union AnnotatedUnion @onUnion = A | B

scalar CustomScalar

scalar AnnotatedScalar @onScalar

enum Site {
DESKTOP
MOBILE
}

enum AnnotatedEnum @onEnum {
ANNOTATED_VALUE @onEnumValue
OTHER_VALUE
}

input InputType {
key: String!
answer: Int = 42
}

input AnnotatedInput @onInputObjectType {
annotatedField: Type @onField
}

extend type Foo {
seven(argument: [String]): Type
}

extend type Foo @onType {}

type NoFields {}

directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
Expand Down
19 changes: 19 additions & 0 deletions src/language/__tests__/schema-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function fieldNodeWithArgs(name, type, args, loc) {
name,
arguments: args,
type,
directives: [],
loc,
};
}
Expand All @@ -60,6 +61,7 @@ function enumValueNode(name, loc) {
return {
kind: 'EnumValueDefinition',
name: nameNode(name, loc),
directives: [],
loc,
};
}
Expand All @@ -70,6 +72,7 @@ function inputValueNode(name, type, defaultValue, loc) {
name,
type,
defaultValue,
directives: [],
loc,
};
}
Expand All @@ -89,6 +92,7 @@ type Hello {
kind: 'ObjectTypeDefinition',
name: nameNode('Hello', loc(6, 11)),
interfaces: [],
directives: [],
fields: [
fieldNode(
nameNode('world', loc(16, 21)),
Expand Down Expand Up @@ -120,6 +124,7 @@ extend type Hello {
kind: 'ObjectTypeDefinition',
name: nameNode('Hello', loc(13, 18)),
interfaces: [],
directives: [],
fields: [
fieldNode(
nameNode('world', loc(23, 28)),
Expand Down Expand Up @@ -151,6 +156,7 @@ type Hello {
kind: 'ObjectTypeDefinition',
name: nameNode('Hello', loc(6, 11)),
interfaces: [],
directives: [],
fields: [
fieldNode(
nameNode('world', loc(16, 21)),
Expand Down Expand Up @@ -182,6 +188,7 @@ type Hello {
kind: 'ObjectTypeDefinition',
name: nameNode('Hello', loc(5, 10)),
interfaces: [ typeNode('World', loc(22, 27)) ],
directives: [],
fields: [],
loc: loc(0, 31),
}
Expand All @@ -205,6 +212,7 @@ type Hello {
typeNode('Wo', loc(22, 24)),
typeNode('rld', loc(26, 29))
],
directives: [],
fields: [],
loc: loc(0, 33),
}
Expand All @@ -224,6 +232,7 @@ type Hello {
{
kind: 'EnumTypeDefinition',
name: nameNode('Hello', loc(5, 10)),
directives: [],
values: [ enumValueNode('WORLD', loc(13, 18)) ],
loc: loc(0, 20),
}
Expand All @@ -243,6 +252,7 @@ type Hello {
{
kind: 'EnumTypeDefinition',
name: nameNode('Hello', loc(5, 10)),
directives: [],
values: [
enumValueNode('WO', loc(13, 15)),
enumValueNode('RLD', loc(17, 20)),
Expand All @@ -268,6 +278,7 @@ interface Hello {
{
kind: 'InterfaceTypeDefinition',
name: nameNode('Hello', loc(11, 16)),
directives: [],
fields: [
fieldNode(
nameNode('world', loc(21, 26)),
Expand Down Expand Up @@ -297,6 +308,7 @@ type Hello {
kind: 'ObjectTypeDefinition',
name: nameNode('Hello', loc(6, 11)),
interfaces: [],
directives: [],
fields: [
fieldNodeWithArgs(
nameNode('world', loc(16, 21)),
Expand Down Expand Up @@ -334,6 +346,7 @@ type Hello {
kind: 'ObjectTypeDefinition',
name: nameNode('Hello', loc(6, 11)),
interfaces: [],
directives: [],
fields: [
fieldNodeWithArgs(
nameNode('world', loc(16, 21)),
Expand Down Expand Up @@ -375,6 +388,7 @@ type Hello {
kind: 'ObjectTypeDefinition',
name: nameNode('Hello', loc(6, 11)),
interfaces: [],
directives: [],
fields: [
fieldNodeWithArgs(
nameNode('world', loc(16, 21)),
Expand Down Expand Up @@ -416,6 +430,7 @@ type Hello {
kind: 'ObjectTypeDefinition',
name: nameNode('Hello', loc(6, 11)),
interfaces: [],
directives: [],
fields: [
fieldNodeWithArgs(
nameNode('world', loc(16, 21)),
Expand Down Expand Up @@ -455,6 +470,7 @@ type Hello {
{
kind: 'UnionTypeDefinition',
name: nameNode('Hello', loc(6, 11)),
directives: [],
types: [ typeNode('World', loc(14, 19)) ],
loc: loc(0, 19),
}
Expand All @@ -474,6 +490,7 @@ type Hello {
{
kind: 'UnionTypeDefinition',
name: nameNode('Hello', loc(6, 11)),
directives: [],
types: [
typeNode('Wo', loc(14, 16)),
typeNode('Rld', loc(19, 22)),
Expand All @@ -496,6 +513,7 @@ type Hello {
{
kind: 'ScalarTypeDefinition',
name: nameNode('Hello', loc(7, 12)),
directives: [],
loc: loc(0, 12),
}
],
Expand All @@ -517,6 +535,7 @@ input Hello {
{
kind: 'InputObjectTypeDefinition',
name: nameNode('Hello', loc(7, 12)),
directives: [],
fields: [
inputValueNode(
nameNode('world', loc(17, 22)),
Expand Down
23 changes: 23 additions & 0 deletions src/language/__tests__/schema-printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,52 @@ type Foo implements Bar {
six(argument: InputType = {key: "value"}): Type
}

type AnnotatedObject @onObject(arg: "value") {
annotatedField(arg: Type = "default" @onArg): Type @onField
}

interface Bar {
one: Type
four(argument: String = "string"): String
}

interface AnnotatedInterface @onInterface {
annotatedField(arg: Type @onArg): Type @onField
}

union Feed = Story | Article | Advert

union AnnotatedUnion @onUnion = A | B

scalar CustomScalar

scalar AnnotatedScalar @onScalar

enum Site {
DESKTOP
MOBILE
}

enum AnnotatedEnum @onEnum {
ANNOTATED_VALUE @onEnumValue
OTHER_VALUE
}

input InputType {
key: String!
answer: Int = 42
}

input AnnotatedInput @onInputObjectType {
annotatedField: Type @onField
}

extend type Foo {
seven(argument: [String]): Type
}

extend type Foo @onType {}

type NoFields {}

directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
Expand Down
9 changes: 9 additions & 0 deletions src/language/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,15 @@ export type ScalarTypeDefinition = {
kind: 'ScalarTypeDefinition';
loc?: ?Location;
name: Name;
directives?: ?Array<Directive>;
}

export type ObjectTypeDefinition = {
kind: 'ObjectTypeDefinition';
loc?: ?Location;
name: Name;
interfaces?: ?Array<NamedType>;
directives?: ?Array<Directive>;
fields: Array<FieldDefinition>;
}

Expand All @@ -305,6 +307,7 @@ export type FieldDefinition = {
name: Name;
arguments: Array<InputValueDefinition>;
type: Type;
directives?: ?Array<Directive>;
}

export type InputValueDefinition = {
Expand All @@ -313,39 +316,45 @@ export type InputValueDefinition = {
name: Name;
type: Type;
defaultValue?: ?Value;
directives?: ?Array<Directive>;
}

export type InterfaceTypeDefinition = {
kind: 'InterfaceTypeDefinition';
loc?: ?Location;
name: Name;
directives?: ?Array<Directive>;
fields: Array<FieldDefinition>;
}

export type UnionTypeDefinition = {
kind: 'UnionTypeDefinition';
loc?: ?Location;
name: Name;
directives?: ?Array<Directive>;
types: Array<NamedType>;
}

export type EnumTypeDefinition = {
kind: 'EnumTypeDefinition';
loc?: ?Location;
name: Name;
directives?: ?Array<Directive>;
values: Array<EnumValueDefinition>;
}

export type EnumValueDefinition = {
kind: 'EnumValueDefinition';
loc?: ?Location;
name: Name;
directives?: ?Array<Directive>;
}

export type InputObjectTypeDefinition = {
kind: 'InputObjectTypeDefinition';
loc?: ?Location;
name: Name;
directives?: ?Array<Directive>;
fields: Array<InputValueDefinition>;
}

Expand Down
Loading