kamilkisiela / graphql-config

One configuration for all your GraphQL tools (supported by most tools, editors & IDEs)
https://the-guild.dev/graphql/config
MIT License
1.16k stars 93 forks source link

SchemaPointer type does not allow for URLs with headers and local type definitions. #1405

Closed basicdays closed 9 months ago

basicdays commented 9 months ago

Issue workflow progress

Progress of the issue based on the Contributor Workflow


Describe the bug

To Reproduce Steps to reproduce the behavior:

/** @type {import('graphql-config').IGraphQLConfig } */
const config = {
    projects: {
        webapp: {
            schema: [
                {
                    "https://gqlservice/graphql": {
                        headers: {
                            Authorization: "token ABC",
                        },
                    },
                },
                "./src/schema/typeDefs.ts",
            ],
        }
    }
};

Running TypeScript against this will produce the following error:

graphql.config.js:31:4 - error TS2322: Type '(string | { [x: string]: { headers: { Authorization: string; }; }; })[]' is not assignable to type 'SchemaPointer'.
  Type '(string | { [x: string]: { headers: { Authorization: string; }; }; })[]' is not assignable to type 'string[]'.
    Type 'string | { [x: string]: { headers: { Authorization: string; }; }; }' is not assignable to type 'string'.
      Type '{ [x: string]: { headers: { Authorization: string; }; }; }' is not assignable to type 'string'.

31    schema: [

Expected behavior

It should pass TypeScript checking.

Environment:

Additional context

The following patch does fix this issue:

diff --git a/node_modules/graphql-config/typings/types.d.ts b/node_modules/graphql-config/typings/types.d.ts
index d78f633..90ac82c 100644
--- a/node_modules/graphql-config/typings/types.d.ts
+++ b/node_modules/graphql-config/typings/types.d.ts
@@ -30,13 +30,13 @@ export interface IGraphQLProjectLegacy {
 }
 export declare type WithList<T> = T | T[];
 export declare type ElementOf<TList> = TList extends Array<infer TElement> ? TElement : never;
-export declare type SchemaPointer = WithList<string> | {
+export declare type SchemaPointer = WithList<string | {
     [url: string]: {
         headers: {
             [name: string]: string;
         };
     };
-}[];
+}>;
 export declare type SchemaPointerSingle = ElementOf<SchemaPointer>;
 export declare type DocumentGlobPathPointer = string;
 export declare type DocumentPointer = WithList<DocumentGlobPathPointer>;