feat(graphiql-react): expose customScalarSchemas for the variable editor - #4448
feat(graphiql-react): expose customScalarSchemas for the variable editor#4448dargmuesli wants to merge 1 commit into
Conversation
The variable editor's live JSON Schema linter assumes every custom scalar
only accepts primitives (string, number, boolean, integer), which is wrong
for any custom scalar that legitimately holds an object or array (a JSON
scalar, a GeoJSON scalar, etc.) - graphql-language-service and
monaco-graphql already support overriding this per-scalar via
scalarSchemas/customScalarSchemas, but @graphiql/react's operation-editor.tsx
registers the schema with Monaco via a hardcoded { uri, schema }, with no
prop to supply the third field.
Adds an optional customScalarSchemas prop to SchemaProps, threaded through
the schema store slice and included in the setSchemaConfig call. Purely
additive - existing behavior is unchanged for anyone not passing it.
Fixes graphql#4447
🦋 Changeset detectedLatest commit: 8313018 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
|
I'll sign the CLA once there is positive feedback on my proposal. Btw, the CLA document template looks off: the fields for me to fill are randomly placed on some page in the second step. |
trevor-scheer
left a comment
There was a problem hiding this comment.
Thanks, lgtm. Could you add a custom scalar usage to the demo app and a cypress test?
packages/graphiql/src/e2e.ts powers the demo and our cypress tests, and the schema behind it is packages/graphiql/test/schema.js. Then add a test in packages/graphiql/cypress/e2e/lint.cy.ts along the existing variable type tests.
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| '@graphiql/react': minor | |||
There was a problem hiding this comment.
Changesets will bump graphiql without this due to its dependency on @graphiql/react, but this will ensure your description below lands in the graphiql changelog which is arguably the more interesting place for users to see it.
| '@graphiql/react': minor | |
| '@graphiql/react': minor | |
| 'graphiql': minor |
Summary
Adds an optional
customScalarSchemasprop to@graphiql/react, so custom GraphQL scalars that legitimately hold objects/arrays (aJSONscalar, aGeoJSONscalar, etc.) aren't flagged by the variable editor's live JSON Schema linter with a false-positive "Incorrect type. Expected one of string, number, boolean, integer." error.Both
graphql-language-service(scalarSchemasoption, added in #3376) andmonaco-graphql(SchemaConfig.customScalarSchemas) already support this per-scalar override.@graphiql/react'soperation-editor.tsxwas the missing link: it registers the schema with Monaco via a hardcoded{ uri, schema }, with no way for a consumer to add the third field.Fixes #4447. See that issue for the full problem description.
Changes
stores/schema.ts: addedcustomScalarSchemas?: Record<string, JSONSchema6>toSchemaProps, threaded throughSchemaSliceandCreateSchemaSlice.components/provider.tsx: destructures the new prop, passes it intocreateSchemaSlice(...).components/operation-editor.tsx: reads it from the store and includes it in themonacoGraphQL.setSchemaConfig(...)call (and its effect's dependency array).Existing behavior for anyone not passing the prop is unchanged.
Usage