( schema: GraphQLSchema, queryPathGlob = process.cwd(), fragDocPath = process.cwd(), apiURL: string )
| 15 | import { plugin as typescriptSdkPlugin } from './sdkPlugin'; |
| 16 | |
| 17 | export const generateTypes = async ( |
| 18 | schema: GraphQLSchema, |
| 19 | queryPathGlob = process.cwd(), |
| 20 | fragDocPath = process.cwd(), |
| 21 | apiURL: string |
| 22 | ) => { |
| 23 | let docs = []; |
| 24 | let fragDocs = []; |
| 25 | |
| 26 | docs = await loadGraphQLDocuments(queryPathGlob); |
| 27 | fragDocs = await loadGraphQLDocuments(fragDocPath); |
| 28 | |
| 29 | // See https://www.graphql-code-generator.com/docs/getting-started/programmatic-usage for more details |
| 30 | const res = await codegen({ |
| 31 | // Filename is not used. This is because the typescript plugin returns a string instead of writing to a file. |
| 32 | filename: process.cwd(), |
| 33 | schema: parse(printSchema(schema)), |
| 34 | documents: [...docs, ...fragDocs], |
| 35 | config: {}, |
| 36 | plugins: [ |
| 37 | { typescript: {} }, |
| 38 | { typescriptOperations: {} }, |
| 39 | { |
| 40 | typescriptSdk: {}, |
| 41 | }, |
| 42 | { AddGeneratedClient: {} }, |
| 43 | ], |
| 44 | pluginMap: { |
| 45 | typescript: { |
| 46 | plugin: typescriptPlugin, |
| 47 | }, |
| 48 | typescriptOperations: { |
| 49 | plugin: typescriptOperationsPlugin, |
| 50 | }, |
| 51 | typescriptSdk: { |
| 52 | plugin: typescriptSdkPlugin, |
| 53 | }, |
| 54 | AddGeneratedClient: AddGeneratedClient(apiURL), |
| 55 | }, |
| 56 | }); |
| 57 | return res; |
| 58 | }; |
| 59 | |
| 60 | const loadGraphQLDocuments = async (globPath: string) => { |
| 61 | let result = []; |
no test coverage detected