Skip to content

GraphQL Annotations - Updated (as metadata) #334

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

Closed
wants to merge 12 commits into from
Closed
6 changes: 6 additions & 0 deletions src/__tests__/starWarsIntrospection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ describe('Star Wars Introspection Tests', () => {
{
name: '__InputValue'
},
{
name: '__Annotation'
},
{
name: '__AnnotationArgument'
},
{
name: '__EnumValue'
},
Expand Down
20 changes: 20 additions & 0 deletions src/jsutils/isScalarValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* @flow */
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

/**
* Returns true if a value is a javascript scalar type: String, Number, Boolean
*/

const JS_SCALAR_RX = /\[object String|Number|Boolean\]/;
const toString = Object.prototype.toString;

export default function isScalarValue(value: mixed): boolean {
return JS_SCALAR_RX.test(toString.call(value));
}
8 changes: 8 additions & 0 deletions src/language/__tests__/kitchen-sink.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ query queryName($foo: ComplexType, $site: Site = MOBILE) {
}
}

@@AnnotationOnOperationDefinition(value: "Foo")
mutation likeStory {
like(story: 123) @defer {
story {
Expand All @@ -35,6 +36,7 @@ mutation likeStory {
}

subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) {
@@AnnotationOnField(default: "Qux")
storyLikeSubscribe(input: $input) {
story {
likers {
Expand All @@ -47,6 +49,7 @@ subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) {
}
}

@@AnnotationOnFragmentDefinition(value: "Bar")
fragment frag on Friend {
foo(size: $size, bar: $b, obj: {key: "value"})
}
Expand All @@ -55,3 +58,8 @@ fragment frag on Friend {
unnamed(truthy: true, falsey: false),
query
}

extend type User {
@@AnnotationOnFieldDefinition(default: "Baz")
name: String
}
6 changes: 6 additions & 0 deletions src/language/__tests__/parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('Parser', () => {
operation: 'query',
name: null,
variableDefinitions: null,
annotations: [],
directives: [],
selectionSet: {
kind: 'SelectionSet',
Expand All @@ -40,6 +41,7 @@ describe('Parser', () => {
loc: { start: 2, end: 7 },
value: 'field' },
arguments: [],
annotations: [],
directives: [],
selectionSet: null } ] } } ]
});
Expand Down Expand Up @@ -238,6 +240,7 @@ fragment ${fragmentName} on Type {
operation: 'query',
name: null,
variableDefinitions: null,
annotations: [],
directives: [],
selectionSet:
{ kind: Kind.SELECTION_SET,
Expand All @@ -261,6 +264,7 @@ fragment ${fragmentName} on Type {
loc: { start: 13, end: 14, source },
value: '4' },
loc: { start: 9, end: 14, source } } ],
annotations: [],
directives: [],
selectionSet:
{ kind: Kind.SELECTION_SET,
Expand All @@ -274,6 +278,7 @@ fragment ${fragmentName} on Type {
loc: { start: 22, end: 24, source },
value: 'id' },
arguments: [],
annotations: [],
directives: [],
selectionSet: null },
{ kind: Kind.FIELD,
Expand All @@ -284,6 +289,7 @@ fragment ${fragmentName} on Type {
loc: { start: 30, end: 34, source },
value: 'name' },
arguments: [],
annotations: [],
directives: [],
selectionSet: null } ] } } ] } } ] }
);
Expand Down
8 changes: 8 additions & 0 deletions src/language/__tests__/printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe('Printer', () => {
}
}

@@AnnotationOnOperationDefinition(value: "Foo")
mutation likeStory {
like(story: 123) @defer {
story {
Expand All @@ -115,6 +116,7 @@ mutation likeStory {
}

subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) {
@@AnnotationOnField(default: "Qux")
storyLikeSubscribe(input: $input) {
story {
likers {
Expand All @@ -127,6 +129,7 @@ subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) {
}
}

@@AnnotationOnFragmentDefinition(value: "Bar")
fragment frag on Friend {
foo(size: $size, bar: $b, obj: {key: "value"})
}
Expand All @@ -135,6 +138,11 @@ fragment frag on Friend {
unnamed(truthy: true, falsey: false)
query
}

extend type User {
@@AnnotationOnFieldDefinition(default: "Baz")
name: String
}
`);

});
Expand Down
1 change: 1 addition & 0 deletions src/language/__tests__/schema-kitchen-sink.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Foo implements Bar {

interface Bar {
one: Type
@@AnnotationOnFieldDefinition(value: "Foo")
four(argument: String = "string"): String
}

Expand Down
Loading