-
I have the following remote schema with some transformations: import { AsyncExecutor, SubschemaConfig } from '@graphql-tools/delegate';
import { introspectSchema, wrapSchema } from '@graphql-tools/wrap';
import { transforms } from './transforms';
const executor: AsyncExecutor = async ({ document, variables }) => {
//...
};
export const createSchema = async () => {
try {
const schema = await introspectSchema(executor);
const wraped = wrapSchema({ schema, executor });
return wraped;
} catch (error) {
throw new Error(
`Unable to create GraphCMS schema!\n\n${error.message}\n\n${error.stack}`
);
}
};
export const createSubschema = async () => {
const schema = await createSchema();
const subschema: SubschemaConfig = {
schema,
transforms,
};
return subschema;
}; How can I pass this schema to the generator? Can I point the custom loader to the async function? Right now, I'm doing codegen programatically, but would prefer to use cli for it's nice GUI and simplicity ;) import { join } from 'path';
import { promises as fs } from 'fs';
import { printSchema, parse } from 'graphql';
import { codegen } from '@graphql-codegen/core';
import { wrapSchema } from '@graphql-tools/wrap';
import * as typescript from '@graphql-codegen/typescript';
import * as typescriptResolvers from '@graphql-codegen/typescript-resolvers';
import { createSubschema } from '../src/graphcms';
const root = join(__dirname, '..');
async function run() {
const filename = 'src/graphcms/types.ts';
const subschema = await createSubschema();
const schema = wrapSchema(subschema);
const output = await codegen({
filename,
schema: parse(printSchema(schema)),
documents: [],
config: {},
plugins: [
{
typescript: {},
typescriptResolvers: {},
},
],
pluginMap: {
typescript,
typescriptResolvers,
},
});
await fs.writeFile(join(root, filename), output);
}
run(); Also I cannot get |
Beta Was this translation helpful? Give feedback.
Answered by
ardatan
Nov 20, 2020
Replies: 1 comment
-
You can export the result of 'createSchema' in a code file then point codegen to that file. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
HriBB
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can export the result of 'createSchema' in a code file then point codegen to that file.