forked from pothos-dev/apollo-hooks-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
35 lines (29 loc) · 949 Bytes
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { executeCodegen } from 'graphql-code-generator'
import { plugin } from '../src/index'
import * as fs from 'fs-extra'
async function readResource(filename: string) {
return await fs.readFile(`${__dirname}/resources/${filename}`, {
encoding: 'utf8',
})
}
test('basic test', async () => {
const schema = await readResource('schema.graphql')
const documents = await readResource('documents.graphql')
const output = await executeCodegen({
schema,
documents,
generates: {
'output.ts': ['apollo-hooks-codegen'],
},
pluginLoader,
})
const fileContent = output.find(it => it.filename == 'output.ts')!.content
expect(fileContent).toMatchSnapshot()
})
function pluginLoader(pluginName: string) {
if (pluginName != 'apollo-hooks-codegen') {
// Must be this exact string, otherwise graphql-code-generator will throw
throw Error(`Cannot find module '${pluginName}'`)
}
return { plugin }
}