diff --git a/.changeset/upset-hats-remain.md b/.changeset/upset-hats-remain.md new file mode 100644 index 0000000..4fd6d01 --- /dev/null +++ b/.changeset/upset-hats-remain.md @@ -0,0 +1,5 @@ +--- +'@0no-co/graphqlsp': minor +--- + +Allow supplying a custom `clientDirectives` which will be mixed in with the base client directives diff --git a/README.md b/README.md index e9269e9..574a7e2 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ when on a TypeScript file or adding a file like [this](https://github.com/0no-co - `tadaOutputLocation` when using `gql.tada` this can be convenient as it automatically generates an `introspection.ts` file for you, just give it the directory to output to and you're done - `tadaDisablePreprocessing` this setting disables the optimisation of `tadaOutput` to a pre-processed TypeScript type, this is off by default. +- `clientDirectives` this setting allows you to specify additional `clientDirectives` which won't be seen as a missing schema-directive. ## Tracking unused fields diff --git a/packages/graphqlsp/README.md b/packages/graphqlsp/README.md index cf5dcb9..bf73052 100644 --- a/packages/graphqlsp/README.md +++ b/packages/graphqlsp/README.md @@ -73,6 +73,7 @@ when on a TypeScript file or adding a file like [this](https://github.com/0no-co from usage tracking, so when they are unused in the component but used in i.e. the normalised cache you won't get annoying warnings. (default `id`, `_id` and `__typename`, example: ['slug']) - `tadaDisablePreprocessing` this setting disables the optimisation of `tadaOutput` to a pre-processed TypeScript type, this is off by default. +- `clientDirectives` this setting allows you to specify additional `clientDirectives` which won't be seen as a missing schema-directive. ## Tracking unused fields diff --git a/packages/graphqlsp/src/diagnostics.ts b/packages/graphqlsp/src/diagnostics.ts index 4d967c8..757bb7a 100644 --- a/packages/graphqlsp/src/diagnostics.ts +++ b/packages/graphqlsp/src/diagnostics.ts @@ -31,9 +31,10 @@ import { } from './persisted'; import { SchemaRef } from './graphql/getSchema'; -const clientDirectives = new Set([ +const BASE_CLIENT_DIRECTIVES = new Set([ 'populate', 'client', + 'unmask', '_unmask', '_optional', '_relayPagination', @@ -419,6 +420,11 @@ const runDiagnostics = ( return undefined; } + const clientDirectives = new Set([ + ...BASE_CLIENT_DIRECTIVES, + ...(info.config.clientDirectives || []), + ]); + const graphQLDiagnostics = getDiagnostics( text, schemaToUse, diff --git a/packages/graphqlsp/src/index.ts b/packages/graphqlsp/src/index.ts index 5db3d78..73876ec 100644 --- a/packages/graphqlsp/src/index.ts +++ b/packages/graphqlsp/src/index.ts @@ -30,6 +30,7 @@ interface Config { templateIsCallExpression?: boolean; shouldCheckForColocatedFragments?: boolean; template?: string; + clientDirectives?: string[]; trackFieldUsage?: boolean; tadaOutputLocation?: string; }