Skip to content

Instantly share code, notes, and snippets.

@valentin-harrang
Created October 22, 2024 12:51
Show Gist options
  • Save valentin-harrang/287f2e941cda020f36e85c9961bf35d1 to your computer and use it in GitHub Desktop.
Save valentin-harrang/287f2e941cda020f36e85c9961bf35d1 to your computer and use it in GitHub Desktop.
import dotenv from 'dotenv';
import type { CodegenConfig } from '@graphql-codegen/cli';
import { AuthService } from './auth.service';
import { AUTH_CONFIG } from './auth.config';
dotenv.config();
const authService = new AuthService(AUTH_CONFIG);
const getConfig = async (): Promise<CodegenConfig> => {
const graphqlUrl = process.env.GRAPHQL_URL || '';
const token = await authService.getToken();
const config: CodegenConfig = {
schema: [
{
[graphqlUrl]: {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
},
},
],
documents: ['./src/**/*.ts'],
ignoreNoDocuments: true,
generates: {
'./src/integration/src/graphql/generated/': {
preset: 'client',
},
'./src/integration/src/graphql/schema.graphql':
{
plugins: ['schema-ast'],
config: {
includeDirectives: true,
},
},
},
hooks: {
afterAllFileWrite: ['npm run format', 'npm run lint:fix || true'],
},
};
return config;
};
export default getConfig();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment