Skip to content

Commit 1933963

Browse files
author
clintwood (Office)
committed
Merge branch 'annotations-wip' into annotations
2 parents fbcd882 + c0e1919 commit 1933963

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

src/type/__tests__/introspection-test.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,75 @@ describe('Introspection', () => {
13501350
});
13511351
});
13521352

1353+
it('introspection of annotations on type', async () => {
1354+
const TestType = new GraphQLObjectType({
1355+
name: 'TestType',
1356+
annotations: {
1357+
anAnnotation: { a: 10 },
1358+
annotationWithTwoArguments: { arg1: 'a', arg2: 'b' }
1359+
},
1360+
fields: {
1361+
testString: { type: GraphQLString },
1362+
}
1363+
});
1364+
1365+
const schema = new GraphQLSchema({ query: TestType });
1366+
const request = `
1367+
{
1368+
__type(name: "TestType") {
1369+
name
1370+
annotations {
1371+
name
1372+
args {
1373+
name
1374+
value
1375+
}
1376+
}
1377+
fields {
1378+
name
1379+
}
1380+
}
1381+
}
1382+
`;
1383+
1384+
return expect(
1385+
await graphql(schema, request)
1386+
).to.deep.equal({
1387+
data: {
1388+
__type: {
1389+
name: 'TestType',
1390+
annotations: [
1391+
{
1392+
name: 'anAnnotation',
1393+
args: [
1394+
{
1395+
name: 'a',
1396+
value: '10',
1397+
},
1398+
],
1399+
},
1400+
{
1401+
name: 'annotationWithTwoArguments',
1402+
args: [
1403+
{
1404+
name: 'arg1',
1405+
value: 'a',
1406+
},
1407+
{
1408+
name: 'arg2',
1409+
value: 'b',
1410+
},
1411+
],
1412+
},
1413+
],
1414+
fields: [ {
1415+
name: 'testString',
1416+
} ]
1417+
}
1418+
}
1419+
});
1420+
});
1421+
13531422
it('introspection of annotations on fields', async () => {
13541423
const TestType = new GraphQLObjectType({
13551424
name: 'TestType',

src/type/introspection.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,14 @@ export const __Type = new GraphQLObjectType({
283283
}
284284
}
285285
},
286-
ofType: { type: __Type }
286+
ofType: { type: __Type },
287+
annotations: {
288+
type: new GraphQLNonNull(new GraphQLList(__Annotation)),
289+
resolve: field => field.annotations &&
290+
Object.keys(field.annotations).map(
291+
name => ({name, args: field.annotations[name]})
292+
) || []
293+
},
287294
})
288295
});
289296

src/utilities/__tests__/schemaPrinter-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ type __Type {
696696
enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
697697
inputFields: [__InputValue!]
698698
ofType: __Type
699+
annotations: [__Annotation]!
699700
}
700701
701702
enum __TypeKind {

0 commit comments

Comments
 (0)