Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion graphql/codegen/src/core/codegen/orm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ export function generateOrm(options: GenerateOrmOptions): GenerateOrmResult {
}

// Re-export generators for direct use
export { generateOrmClientFile, generateQueryBuilderFile, generateSelectTypesFile } from './client-generator';
export {
generateOrmClientFile,
generateQueryBuilderFile,
generateSelectTypesFile,
} from './client-generator';
export { generateModelFile, generateAllModelFiles } from './model-generator';
export { generateCustomQueryOpsFile, generateCustomMutationOpsFile } from './custom-ops-generator';
export { generateModelsBarrel, generateTypesBarrel } from './barrel';
6 changes: 6 additions & 0 deletions graphql/codegen/src/core/codegen/templates/client.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface GraphQLClientConfig {
endpoint: string;
/** Default headers to include in all requests */
headers?: Record<string, string>;
/** Dynamic headers callback called on every request */
getHeaders?: () => Record<string, string>;
}

let globalConfig: GraphQLClientConfig | null = null;
Expand Down Expand Up @@ -139,12 +141,14 @@ export async function execute<
options?: ExecuteOptions
): Promise<TData> {
const config = getConfig();
const dynamicHeaders = config.getHeaders?.() ?? {};

const response = await fetch(config.endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...config.headers,
...dynamicHeaders,
...options?.headers,
},
body: JSON.stringify({
Expand Down Expand Up @@ -180,12 +184,14 @@ export async function executeWithErrors<
options?: ExecuteOptions
): Promise<{ data: TData | null; errors: GraphQLError[] | null }> {
const config = getConfig();
const dynamicHeaders = config.getHeaders?.() ?? {};

const response = await fetch(config.endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...config.headers,
...dynamicHeaders,
...options?.headers,
},
body: JSON.stringify({
Expand Down
6 changes: 6 additions & 0 deletions graphql/codegen/src/core/codegen/templates/client.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export interface GraphQLClientConfig {
endpoint: string;
/** Default headers to include in all requests */
headers?: Record<string, string>;
/** Dynamic headers callback called on every request */
getHeaders?: () => Record<string, string>;
}

let globalConfig: GraphQLClientConfig | null = null;
Expand Down Expand Up @@ -183,6 +185,7 @@ export async function execute<
): Promise<TData> {
const config = getConfig();
const url = new URL(config.endpoint);
const dynamicHeaders = config.getHeaders?.() ?? {};

const body = JSON.stringify({
query: document,
Expand All @@ -194,6 +197,7 @@ export async function execute<
headers: {
'Content-Type': 'application/json',
...config.headers,
...dynamicHeaders,
...options?.headers,
},
};
Expand Down Expand Up @@ -234,6 +238,7 @@ export async function executeWithErrors<
): Promise<{ data: TData | null; errors: GraphQLError[] | null }> {
const config = getConfig();
const url = new URL(config.endpoint);
const dynamicHeaders = config.getHeaders?.() ?? {};

const body = JSON.stringify({
query: document,
Expand All @@ -245,6 +250,7 @@ export async function executeWithErrors<
headers: {
'Content-Type': 'application/json',
...config.headers,
...dynamicHeaders,
...options?.headers,
},
};
Expand Down
Loading