Skip to content

Files

Latest commit

487b5ed · Nov 2, 2024

History

History

cm6-graphql

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Mar 1, 2024
Aug 24, 2024
Oct 30, 2022
Oct 30, 2022
Nov 2, 2024
Oct 30, 2022
Jul 1, 2024
Nov 2, 2024
Jan 18, 2023
Jan 21, 2023

CodeMirror 6 GraphQL Language extension

NPM npm downloads License Discord Channel

Provides CodeMirror 6 extension with a parser mode for GraphQL along with autocomplete and linting powered by your GraphQL Schema.

Getting Started

npm install cm6-graphql

CodeMirror 6 customization is done through extensions. This package is an extension that customizes CodeMirror 6 for GraphQL.

import { basicSetup, EditorView } from 'codemirror';
import { graphql } from 'cm6-graphql';

const view = new EditorView({
  doc: `mutation mutationName {
    setString(value: "newString")
  }`,
  extensions: [basicSetup, graphql(myGraphQLSchema)],
  parent: document.body,
});

Note: You have to provide a theme to CodeMirror 6 for the styling you want. You can take a look at this example or see the CodeMirror 6 documentation examples for more details.

Updating schema

If you need to dynamically update the GraphQL schema used in the editor, you can call updateSchema with the CodeMirror EditorView instance and the new schema

import { updateSchema } from 'cm6-graphql';

const onNewSchema = schema => {
  updateSchema(view, schema);
};