2020-07-02 11:42:06 +08:00
|
|
|
import { graphql } from 'graphql'
|
2019-09-23 09:28:27 +08:00
|
|
|
import {
|
2020-04-07 20:19:45 +08:00
|
|
|
arg,
|
2019-09-23 09:28:27 +08:00
|
|
|
booleanArg,
|
|
|
|
|
floatArg,
|
|
|
|
|
idArg,
|
|
|
|
|
intArg,
|
2020-04-07 20:19:45 +08:00
|
|
|
makeSchema,
|
2020-11-14 03:19:15 +08:00
|
|
|
NexusGraphQLSchema,
|
2019-09-23 09:28:27 +08:00
|
|
|
objectType,
|
2020-04-07 20:19:45 +08:00
|
|
|
queryField,
|
|
|
|
|
stringArg,
|
2020-07-02 11:42:06 +08:00
|
|
|
} from '../src/core'
|
2019-09-23 09:28:27 +08:00
|
|
|
|
2020-11-14 03:19:15 +08:00
|
|
|
let schema: NexusGraphQLSchema
|
|
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
|
schema = makeSchema({
|
|
|
|
|
types: [
|
|
|
|
|
queryField('user', {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
type: 'User',
|
|
|
|
|
args: {
|
|
|
|
|
int: intArg(),
|
|
|
|
|
bool: booleanArg(),
|
|
|
|
|
float: floatArg(),
|
|
|
|
|
id: idArg(),
|
|
|
|
|
str: stringArg(),
|
|
|
|
|
},
|
|
|
|
|
resolve: () => ({ id: `User:1`, name: 'Test User' }),
|
|
|
|
|
}),
|
|
|
|
|
objectType({
|
|
|
|
|
name: 'User',
|
|
|
|
|
definition(t) {
|
|
|
|
|
t.id('id')
|
|
|
|
|
t.string('name')
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
outputs: false,
|
|
|
|
|
shouldGenerateArtifacts: false,
|
2020-07-02 11:42:06 +08:00
|
|
|
})
|
2020-11-14 03:19:15 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can be implemented by object types', async () => {
|
|
|
|
|
expect(
|
2022-02-18 01:47:40 +08:00
|
|
|
await graphql({
|
2020-11-14 03:19:15 +08:00
|
|
|
schema,
|
2022-02-18 01:47:40 +08:00
|
|
|
source: `
|
2020-11-14 03:19:15 +08:00
|
|
|
{
|
|
|
|
|
user(int: 1, bool: true, float: 123.45, str: "Test") {
|
|
|
|
|
id
|
|
|
|
|
name
|
2019-09-23 09:28:27 +08:00
|
|
|
}
|
2020-11-14 03:19:15 +08:00
|
|
|
}
|
2022-02-18 01:47:40 +08:00
|
|
|
`,
|
|
|
|
|
})
|
2020-11-14 03:19:15 +08:00
|
|
|
).toMatchSnapshot()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('throws if the arg is not provided to the type', async () => {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
expect(() => arg({ type: null })).toThrowErrorMatchingSnapshot()
|
2020-07-02 11:42:06 +08:00
|
|
|
})
|