11import {
22 GraphQLID ,
3+ GraphQLInputObjectType ,
34 GraphQLInt ,
45 GraphQLList ,
56 GraphQLNonNull ,
67 GraphQLObjectType ,
78 GraphQLString ,
89} from 'graphql' ;
9- import getSchemaFromData from './getSchemaFromData' ;
1010import type { ObjMap } from 'graphql/jsutils/ObjMap' ;
11+ import { expect , test } from 'vitest' ;
12+ import getSchemaFromData from './getSchemaFromData' ;
1113
1214const data = {
1315 posts : [
@@ -105,36 +107,38 @@ const QueryType = new GraphQLObjectType({
105107
106108test ( 'creates one type per data type' , ( ) => {
107109 const typeMap = getSchemaFromData (
108- data ,
110+ data
109111 ) . getTypeMap ( ) as ObjMap < GraphQLObjectType > ;
110112 expect ( typeMap . Post . name ) . toEqual ( PostType . name ) ;
111113 expect ( Object . keys ( typeMap . Post . getFields ( ) ) ) . toEqual (
112- Object . keys ( PostType . getFields ( ) ) ,
114+ Object . keys ( PostType . getFields ( ) )
113115 ) ;
114116 expect ( typeMap . User . name ) . toEqual ( UserType . name ) ;
115117 expect ( Object . keys ( typeMap . User . getFields ( ) ) ) . toEqual (
116- Object . keys ( UserType . getFields ( ) ) ,
118+ Object . keys ( UserType . getFields ( ) )
117119 ) ;
118120} ) ;
119121
120122test ( 'creates one field per relationship' , ( ) => {
121123 const typeMap = getSchemaFromData (
122- data ,
124+ data
123125 ) . getTypeMap ( ) as ObjMap < GraphQLObjectType > ;
124126 expect ( Object . keys ( typeMap . Post . getFields ( ) ) ) . toContain ( 'User' ) ;
125127} ) ;
126128
127129test ( 'creates one field per reverse relationship' , ( ) => {
128130 const typeMap = getSchemaFromData (
129- data ,
131+ data
130132 ) . getTypeMap ( ) as ObjMap < GraphQLObjectType > ;
131133 expect ( Object . keys ( typeMap . User . getFields ( ) ) ) . toContain ( 'Posts' ) ;
132134} ) ;
133135
134136test ( 'creates three query fields per data type' , ( ) => {
135137 // biome-ignore lint/style/noNonNullAssertion: It's only a test
136138 const queries = getSchemaFromData ( data ) . getQueryType ( ) ! . getFields ( ) ;
137- expect ( queries . Post . type . name ) . toEqual ( PostType . name ) ;
139+ expect ( ( queries . Post . type as GraphQLObjectType ) . name ) . toEqual (
140+ PostType . name
141+ ) ;
138142 expect ( queries . Post . args ) . toEqual ( [
139143 expect . objectContaining ( {
140144 name : 'id' ,
@@ -154,7 +158,9 @@ test('creates three query fields per data type', () => {
154158 expect ( queries . allPosts . args [ 4 ] . type . toString ( ) ) . toEqual ( 'PostFilter' ) ;
155159 expect ( queries . _allPostsMeta . type . toString ( ) ) . toEqual ( 'ListMetadata' ) ;
156160
157- expect ( queries . User . type . name ) . toEqual ( UserType . name ) ;
161+ expect ( ( queries . User . type as GraphQLObjectType ) . name ) . toEqual (
162+ UserType . name
163+ ) ;
158164 expect ( queries . User . args ) . toEqual ( [
159165 expect . objectContaining ( {
160166 name : 'id' ,
@@ -178,7 +184,9 @@ test('creates three query fields per data type', () => {
178184test ( 'creates three mutation fields per data type' , ( ) => {
179185 // biome-ignore lint/style/noNonNullAssertion: It's only a test
180186 const mutations = getSchemaFromData ( data ) . getMutationType ( ) ! . getFields ( ) ;
181- expect ( mutations . createPost . type . name ) . toEqual ( PostType . name ) ;
187+ expect ( ( mutations . createPost . type as GraphQLObjectType ) . name ) . toEqual (
188+ PostType . name
189+ ) ;
182190 expect ( mutations . createPost . args ) . toEqual ( [
183191 expect . objectContaining ( {
184192 name : 'title' ,
@@ -193,7 +201,9 @@ test('creates three mutation fields per data type', () => {
193201 type : new GraphQLNonNull ( GraphQLID ) ,
194202 } ) ,
195203 ] ) ;
196- expect ( mutations . updatePost . type . name ) . toEqual ( PostType . name ) ;
204+ expect ( ( mutations . updatePost . type as GraphQLObjectType ) . name ) . toEqual (
205+ PostType . name
206+ ) ;
197207 expect ( mutations . updatePost . args ) . toEqual ( [
198208 expect . objectContaining ( {
199209 name : 'id' ,
@@ -212,21 +222,27 @@ test('creates three mutation fields per data type', () => {
212222 type : GraphQLID ,
213223 } ) ,
214224 ] ) ;
215- expect ( mutations . removePost . type . name ) . toEqual ( PostType . name ) ;
225+ expect ( ( mutations . removePost . type as GraphQLObjectType ) . name ) . toEqual (
226+ PostType . name
227+ ) ;
216228 expect ( mutations . removePost . args ) . toEqual ( [
217229 expect . objectContaining ( {
218230 name : 'id' ,
219231 type : new GraphQLNonNull ( GraphQLID ) ,
220232 } ) ,
221233 ] ) ;
222- expect ( mutations . createUser . type . name ) . toEqual ( UserType . name ) ;
234+ expect ( ( mutations . createUser . type as GraphQLObjectType ) . name ) . toEqual (
235+ UserType . name
236+ ) ;
223237 expect ( mutations . createUser . args ) . toEqual ( [
224238 expect . objectContaining ( {
225239 name : 'name' ,
226240 type : new GraphQLNonNull ( GraphQLString ) ,
227241 } ) ,
228242 ] ) ;
229- expect ( mutations . updateUser . type . name ) . toEqual ( UserType . name ) ;
243+ expect ( ( mutations . updateUser . type as GraphQLObjectType ) . name ) . toEqual (
244+ UserType . name
245+ ) ;
230246 expect ( mutations . updateUser . args ) . toEqual ( [
231247 expect . objectContaining ( {
232248 name : 'id' ,
@@ -237,7 +253,9 @@ test('creates three mutation fields per data type', () => {
237253 type : GraphQLString ,
238254 } ) ,
239255 ] ) ;
240- expect ( mutations . removeUser . type . name ) . toEqual ( UserType . name ) ;
256+ expect ( ( mutations . removeUser . type as GraphQLObjectType ) . name ) . toEqual (
257+ UserType . name
258+ ) ;
241259 expect ( mutations . removeUser . args ) . toEqual ( [
242260 expect . objectContaining ( {
243261 name : 'id' ,
@@ -251,20 +269,22 @@ test('creates the mutation *Input type for createMany', () => {
251269 const mutations = getSchemaFromData ( data ) . getMutationType ( ) ! . getFields ( ) ;
252270 const createManyPostInputType = mutations . createManyPost . args [ 0 ] . type ;
253271 expect ( createManyPostInputType . toString ( ) ) . toEqual ( '[PostInput]' ) ;
254- expect ( createManyPostInputType . ofType . getFields ( ) ) . toEqual ( {
255- title : expect . objectContaining ( {
256- type : new GraphQLNonNull ( GraphQLString ) ,
257- name : 'title' ,
258- } ) ,
259- views : expect . objectContaining ( {
260- type : new GraphQLNonNull ( GraphQLInt ) ,
261- name : 'views' ,
262- } ) ,
263- user_id : expect . objectContaining ( {
264- type : new GraphQLNonNull ( GraphQLID ) ,
265- name : 'user_id' ,
266- } ) ,
267- } ) ;
272+ expect ( ( createManyPostInputType as GraphQLList < any > ) . ofType . getFields ( ) ) . toEqual (
273+ {
274+ title : expect . objectContaining ( {
275+ type : new GraphQLNonNull ( GraphQLString ) ,
276+ name : 'title' ,
277+ } ) ,
278+ views : expect . objectContaining ( {
279+ type : new GraphQLNonNull ( GraphQLInt ) ,
280+ name : 'views' ,
281+ } ) ,
282+ user_id : expect . objectContaining ( {
283+ type : new GraphQLNonNull ( GraphQLID ) ,
284+ name : 'user_id' ,
285+ } ) ,
286+ }
287+ ) ;
268288} ) ;
269289
270290test ( 'pluralizes and capitalizes correctly' , ( ) => {
0 commit comments