-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcodegen.ts
More file actions
37 lines (30 loc) · 1.07 KB
/
codegen.ts
File metadata and controls
37 lines (30 loc) · 1.07 KB
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
36
37
import * as dotenv from 'dotenv';
import baseConfigs from '@snapwp/codegen-config';
import { generateGraphqlUrl } from '@snapwp/core';
import type { CodegenConfig } from '@graphql-codegen/cli';
dotenv.config( { path: '../../.env' } );
// If there's no explicit SITE_URL, it's the same as the HOME_URL.
const homeUrl =
process.env.NEXT_PUBLIC_WP_SITE_URL ||
process.env.WP_SITE_URL ||
process.env.NEXT_PUBLIC_WP_HOME_URL;
const graphqlEndpoint =
process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT || process.env.GRAPHQL_ENDPOINT;
// This is necessary because we don't have access to the config manager.
const graphqlUrl = generateGraphqlUrl( homeUrl, graphqlEndpoint );
const config: CodegenConfig = {
...baseConfigs,
documents: './src/**/*.graphql',
// Use the schema file if it's set by CI.
schema: process.env.GRAPHQL_SCHEMA_FILE ?? [
{
[ graphqlUrl ]: {
headers: {
Authorization: `${ process.env.INTROSPECTION_TOKEN }`,
},
},
},
],
};
// eslint-disable-next-line import/no-default-export -- default export is required for compatibility.
export default config;