11import { expect } from 'chai' ;
22import { describe , it } from 'mocha' ;
33
4+ import type {
5+ GraphQLEnumType ,
6+ GraphQLInputObjectType ,
7+ GraphQLObjectType ,
8+ } from '../../type/definition' ;
9+ import type { GraphQLDirective } from '../../type/directives' ;
10+
411import { buildSchema } from '../buildASTSchema' ;
512import { resolveSchemaCoordinate } from '../resolveSchemaCoordinate' ;
613
714describe ( 'resolveSchemaCoordinate' , ( ) => {
8- const schema : any = buildSchema ( `
15+ const schema = buildSchema ( `
916 type Query {
1017 searchBusiness(criteria: SearchCriteria!): [Business]
1118 }
@@ -31,116 +38,147 @@ describe('resolveSchemaCoordinate', () => {
3138 ` ) ;
3239
3340 it ( 'resolves a Named Type' , ( ) => {
34- const expected = schema . getType ( 'Business' ) ;
35- expect ( expected ) . not . to . equal ( undefined ) ;
36- expect ( resolveSchemaCoordinate ( schema , 'Business' ) ) . to . equal ( expected ) ;
41+ expect ( resolveSchemaCoordinate ( schema , 'Business' ) ) . to . deep . equal ( {
42+ kind : 'NamedType' ,
43+ type : schema . getType ( 'Business' ) ,
44+ } ) ;
3745
38- expect ( resolveSchemaCoordinate ( schema , 'String' ) ) . to . equal (
39- schema . getType ( 'String' ) ,
40- ) ;
46+ expect ( resolveSchemaCoordinate ( schema , 'String' ) ) . to . deep . equal ( {
47+ kind : 'NamedType' ,
48+ type : schema . getType ( 'String' ) ,
49+ } ) ;
4150
42- expect ( resolveSchemaCoordinate ( schema , 'private' ) ) . to . equal ( undefined ) ;
51+ expect ( resolveSchemaCoordinate ( schema , 'private' ) ) . to . deep . equal ( undefined ) ;
4352
44- expect ( resolveSchemaCoordinate ( schema , 'Unknown' ) ) . to . equal ( undefined ) ;
53+ expect ( resolveSchemaCoordinate ( schema , 'Unknown' ) ) . to . deep . equal ( undefined ) ;
4554 } ) ;
4655
4756 it ( 'resolves a Type Field' , ( ) => {
48- const expected = schema . getType ( 'Business' ) . getFields ( ) . name ;
49- expect ( expected ) . not . to . equal ( undefined ) ;
50- expect ( resolveSchemaCoordinate ( schema , 'Business.name' ) ) . to . equal ( expected ) ;
51-
52- expect ( resolveSchemaCoordinate ( schema , 'Business.unknown' ) ) . to . equal (
57+ const type = schema . getType ( 'Business' ) as GraphQLObjectType ;
58+ const field = type . getFields ( ) . name ;
59+ expect ( resolveSchemaCoordinate ( schema , 'Business.name' ) ) . to . deep . equal ( {
60+ kind : 'Field' ,
61+ type,
62+ field,
63+ } ) ;
64+
65+ expect ( resolveSchemaCoordinate ( schema , 'Business.unknown' ) ) . to . deep . equal (
5366 undefined ,
5467 ) ;
5568
56- expect ( resolveSchemaCoordinate ( schema , 'Unknown.field' ) ) . to . equal (
69+ expect ( resolveSchemaCoordinate ( schema , 'Unknown.field' ) ) . to . deep . equal (
5770 undefined ,
5871 ) ;
5972
60- expect ( resolveSchemaCoordinate ( schema , 'String.field' ) ) . to . equal ( undefined ) ;
73+ expect ( resolveSchemaCoordinate ( schema , 'String.field' ) ) . to . deep . equal (
74+ undefined ,
75+ ) ;
6176 } ) ;
6277
6378 it ( 'does not resolve meta-fields' , ( ) => {
64- expect ( resolveSchemaCoordinate ( schema , 'Business.__typename' ) ) . to . equal (
65- undefined ,
66- ) ;
79+ expect (
80+ resolveSchemaCoordinate ( schema , 'Business.__typename' ) ,
81+ ) . to . deep . equal ( undefined ) ;
6782 } ) ;
6883
6984 it ( 'resolves a Input Field' , ( ) => {
70- const expected = schema . getType ( 'SearchCriteria' ) . getFields ( ) . filter ;
71- expect ( expected ) . not . to . equal ( undefined ) ;
72- expect ( resolveSchemaCoordinate ( schema , 'SearchCriteria.filter' ) ) . to . equal (
73- expected ,
74- ) ;
85+ const type = schema . getType ( 'SearchCriteria' ) as GraphQLInputObjectType ;
86+ const inputField = type . getFields ( ) . filter ;
87+ expect (
88+ resolveSchemaCoordinate ( schema , 'SearchCriteria.filter' ) ,
89+ ) . to . deep . equal ( {
90+ kind : 'InputField' ,
91+ type,
92+ inputField,
93+ } ) ;
7594
76- expect ( resolveSchemaCoordinate ( schema , 'SearchCriteria.unknown' ) ) . to . equal (
77- undefined ,
78- ) ;
95+ expect (
96+ resolveSchemaCoordinate ( schema , 'SearchCriteria.unknown' ) ,
97+ ) . to . deep . equal ( undefined ) ;
7998 } ) ;
8099
81100 it ( 'resolves a Enum Value' , ( ) => {
82- const expected = schema . getType ( 'SearchFilter' ) . getValue ( 'OPEN_NOW' ) ;
83- expect ( expected ) . not . to . equal ( undefined ) ;
84- expect ( resolveSchemaCoordinate ( schema , 'SearchFilter.OPEN_NOW' ) ) . to . equal (
85- expected ,
86- ) ;
101+ const type = schema . getType ( 'SearchFilter' ) as GraphQLEnumType ;
102+ const enumValue = type . getValue ( 'OPEN_NOW' ) ;
103+ expect (
104+ resolveSchemaCoordinate ( schema , 'SearchFilter.OPEN_NOW' ) ,
105+ ) . to . deep . equal ( {
106+ kind : 'EnumValue' ,
107+ type,
108+ enumValue,
109+ } ) ;
87110
88- expect ( resolveSchemaCoordinate ( schema , 'SearchFilter.UNKNOWN' ) ) . to . equal (
89- undefined ,
90- ) ;
111+ expect (
112+ resolveSchemaCoordinate ( schema , 'SearchFilter.UNKNOWN' ) ,
113+ ) . to . deep . equal ( undefined ) ;
91114 } ) ;
92115
93116 it ( 'resolves a Field Argument' , ( ) => {
94- const expected = schema
95- . getType ( 'Query' )
96- . getFields ( )
97- . searchBusiness . args . find ( ( arg : any ) => arg . name === 'criteria' ) ;
98- expect ( expected ) . not . to . equal ( undefined ) ;
117+ const type = schema . getType ( 'Query' ) as GraphQLObjectType ;
118+ const field = type . getFields ( ) . searchBusiness ;
119+ const fieldArgument = field . args . find ( ( arg ) => arg . name === 'criteria' ) ;
99120 expect (
100121 resolveSchemaCoordinate ( schema , 'Query.searchBusiness(criteria:)' ) ,
101- ) . to . equal ( expected ) ;
122+ ) . to . deep . equal ( {
123+ kind : 'FieldArgument' ,
124+ type,
125+ field,
126+ fieldArgument,
127+ } ) ;
102128
103- expect ( resolveSchemaCoordinate ( schema , 'Business.name(unknown:)' ) ) . to . equal (
104- undefined ,
105- ) ;
129+ expect (
130+ resolveSchemaCoordinate ( schema , 'Business.name(unknown:)' ) ,
131+ ) . to . deep . equal ( undefined ) ;
106132
107- expect ( resolveSchemaCoordinate ( schema , 'Unknown.field(arg:)' ) ) . to . equal (
108- undefined ,
109- ) ;
133+ expect (
134+ resolveSchemaCoordinate ( schema , 'Unknown.field(arg:)' ) ,
135+ ) . to . deep . equal ( undefined ) ;
110136
111- expect ( resolveSchemaCoordinate ( schema , 'Business.unknown(arg:)' ) ) . to . equal (
112- undefined ,
113- ) ;
137+ expect (
138+ resolveSchemaCoordinate ( schema , 'Business.unknown(arg:)' ) ,
139+ ) . to . deep . equal ( undefined ) ;
114140
115141 expect (
116142 resolveSchemaCoordinate ( schema , 'SearchCriteria.name(arg:)' ) ,
117- ) . to . equal ( undefined ) ;
143+ ) . to . deep . equal ( undefined ) ;
118144 } ) ;
119145
120146 it ( 'resolves a Directive' , ( ) => {
121- const expected = schema . getDirective ( 'private' ) ;
122- expect ( expected ) . not . to . equal ( undefined ) ;
123- expect ( resolveSchemaCoordinate ( schema , '@private' ) ) . to . equal ( expected ) ;
147+ expect ( resolveSchemaCoordinate ( schema , '@private' ) ) . to . deep . equal ( {
148+ kind : 'Directive' ,
149+ directive : schema . getDirective ( 'private' ) ,
150+ } ) ;
151+
152+ expect ( resolveSchemaCoordinate ( schema , '@deprecated' ) ) . to . deep . equal ( {
153+ kind : 'Directive' ,
154+ directive : schema . getDirective ( 'deprecated' ) ,
155+ } ) ;
124156
125- expect ( resolveSchemaCoordinate ( schema , '@unknown' ) ) . to . equal ( undefined ) ;
157+ expect ( resolveSchemaCoordinate ( schema , '@unknown' ) ) . to . deep . equal (
158+ undefined ,
159+ ) ;
126160
127- expect ( resolveSchemaCoordinate ( schema , '@Business' ) ) . to . equal ( undefined ) ;
161+ expect ( resolveSchemaCoordinate ( schema , '@Business' ) ) . to . deep . equal (
162+ undefined ,
163+ ) ;
128164 } ) ;
129165
130166 it ( 'resolves a Directive Argument' , ( ) => {
131- const expected = schema
132- . getDirective ( 'private' )
133- . args . find ( ( arg : any ) => arg . name === 'scope' ) ;
134- expect ( expected ) . not . to . equal ( undefined ) ;
135- expect ( resolveSchemaCoordinate ( schema , '@private(scope:)' ) ) . to . equal (
136- expected ,
167+ const directive = schema . getDirective ( 'private' ) as GraphQLDirective ;
168+ const directiveArgument = directive . args . find (
169+ ( arg ) => arg . name === 'scope' ,
137170 ) ;
171+ expect ( resolveSchemaCoordinate ( schema , '@private(scope:)' ) ) . to . deep . equal ( {
172+ kind : 'DirectiveArgument' ,
173+ directive,
174+ directiveArgument,
175+ } ) ;
138176
139- expect ( resolveSchemaCoordinate ( schema , '@private(unknown:)' ) ) . to . equal (
177+ expect ( resolveSchemaCoordinate ( schema , '@private(unknown:)' ) ) . to . deep . equal (
140178 undefined ,
141179 ) ;
142180
143- expect ( resolveSchemaCoordinate ( schema , '@unknown(arg:)' ) ) . to . equal (
181+ expect ( resolveSchemaCoordinate ( schema , '@unknown(arg:)' ) ) . to . deep . equal (
144182 undefined ,
145183 ) ;
146184 } ) ;
0 commit comments