Skip to content

Commit

Permalink
fix(cm6-graphql): Fix query token used as field name (#2995)
Browse files Browse the repository at this point in the history
* fix(cm6-graphql): Fix query token used as field name

Use @extend instead of @Specialize
Fixed tests

* Create eighty-spiders-crash.md

* build cm6-graphql

* fix build

* addressed pr feedback

* yarn format
  • Loading branch information
imolorhe authored Jan 21, 2023
1 parent f788e65 commit 5f276c4
Show file tree
Hide file tree
Showing 26 changed files with 3,716 additions and 1,230 deletions.
6 changes: 6 additions & 0 deletions .changeset/eighty-spiders-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cm6-graphql": patch
"graphiql": patch
---

fix(cm6-graphql): Fix query token used as field name
2 changes: 1 addition & 1 deletion examples/cm6-graphql-parcel/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>CM6 GraphQL Editor Example</title>
<title>Code Mirror 6 GraphQL Editor Example</title>
</head>

<body>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
"npm": "please_use_yarn_instead"
},
"scripts": {
"build": "yarn build:clean && yarn build:packages && yarn build:graphiql-react && yarn build:graphiql-plugin-explorer && yarn build:graphiql-plugin-code-exporter && yarn build:graphiql",
"build": "yarn build:clean && yarn build:cm6-graphql && yarn build:packages && yarn build:graphiql-react && yarn build:graphiql-plugin-explorer && yarn build:graphiql-plugin-code-exporter && yarn build:graphiql",
"build-bundles": "yarn prebuild-bundles && wsrun -p -m -s build-bundles",
"build-bundles-clean": "rimraf '{packages,examples,plugins}/**/{bundle,cdn,webpack}' && yarn workspace graphiql run build-bundles-clean",
"build-clean": "wsrun -m build-clean ",
"build-demo": "wsrun -m -s build-demo",
"build-docs": "rimraf 'packages/graphiql/typedoc' && typedoc 'packages'",
"build:clean": "yarn tsc --clean && yarn tsc --clean resources/tsconfig.graphiql.json",
"build:cm6-graphql": "yarn workspace cm6-graphql run build",
"build:graphiql": "yarn tsc resources/tsconfig.graphiql.json",
"build:graphiql-plugin-explorer": "yarn workspace @graphiql/plugin-explorer run build",
"build:graphiql-plugin-code-exporter": "yarn workspace @graphiql/plugin-code-exporter run build",
Expand Down
25 changes: 20 additions & 5 deletions packages/cm6-graphql/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,35 @@

### Patch Changes

- [#2931](https://github.com/graphql/graphiql/pull/2931) [`f7addb20`](https://github.com/graphql/graphiql/commit/f7addb20c4a558fbfb4112c8ff095bbc8f9d9147) Thanks [@B2o5T](https://github.com/B2o5T)! - enable `no-negated-condition` and `no-else-return` rules
- [#2931](https://github.com/graphql/graphiql/pull/2931)
[`f7addb20`](https://github.com/graphql/graphiql/commit/f7addb20c4a558fbfb4112c8ff095bbc8f9d9147)
Thanks [@B2o5T](https://github.com/B2o5T)! - enable `no-negated-condition` and
`no-else-return` rules

- [#2922](https://github.com/graphql/graphiql/pull/2922) [`d1fcad72`](https://github.com/graphql/graphiql/commit/d1fcad72607e2789517dfe4936b5ec604e46762b) Thanks [@B2o5T](https://github.com/B2o5T)! - extends `plugin:import/recommended` and fix warnings
- [#2922](https://github.com/graphql/graphiql/pull/2922)
[`d1fcad72`](https://github.com/graphql/graphiql/commit/d1fcad72607e2789517dfe4936b5ec604e46762b)
Thanks [@B2o5T](https://github.com/B2o5T)! - extends
`plugin:import/recommended` and fix warnings

- [#2992](https://github.com/graphql/graphiql/pull/2992) [`cc245246`](https://github.com/graphql/graphiql/commit/cc2452467688f3cdcd7a196dddf47e3b81367d62) Thanks [@acao](https://github.com/acao)! - fix tsconfig reference, new netlify deploy
- [#2992](https://github.com/graphql/graphiql/pull/2992)
[`cc245246`](https://github.com/graphql/graphiql/commit/cc2452467688f3cdcd7a196dddf47e3b81367d62)
Thanks [@acao](https://github.com/acao)! - fix tsconfig reference, new netlify
deploy

## 0.0.1

### Patch Changes

- [#2867](https://github.com/graphql/graphiql/pull/2867) [`9fd12838`](https://github.com/graphql/graphiql/commit/9fd128381a86220a7c658f21d72baa8eea45a8af) Thanks [@imolorhe](https://github.com/imolorhe)! - fix: fixed "Mark decorations may not be empty" error
- [#2867](https://github.com/graphql/graphiql/pull/2867)
[`9fd12838`](https://github.com/graphql/graphiql/commit/9fd128381a86220a7c658f21d72baa8eea45a8af)
Thanks [@imolorhe](https://github.com/imolorhe)! - fix: fixed "Mark
decorations may not be empty" error

## 0.0.0

### Patch Changes

- [#2852](https://github.com/graphql/graphiql/pull/2852) [`20869583`](https://github.com/graphql/graphiql/commit/20869583eff563f5d6494e93302a835f0e034f4b) Thanks [@acao](https://github.com/acao)! - First release of a modern codemirror 6 mode for graphql by @imolorhe!
- [#2852](https://github.com/graphql/graphiql/pull/2852)
[`20869583`](https://github.com/graphql/graphiql/commit/20869583eff563f5d6494e93302a835f0e034f4b)
Thanks [@acao](https://github.com/acao)! - First release of a modern
codemirror 6 mode for graphql by @imolorhe!
77 changes: 24 additions & 53 deletions packages/cm6-graphql/__tests__/cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

==>

Document(OperationDefinition(SelectionSet(Selection(Field(Name)))))
Document(OperationDefinition(SelectionSet("{",Selection(Field(FieldName)),"}")))

# Named query

query a { hello }

==>

Document(OperationDefinition(OperationType,Name,SelectionSet(Selection(Field(Name)))))
Document(OperationDefinition(OperationType,Name,SelectionSet("{",Selection(Field(FieldName)),"}")))

# Nested query

Expand All @@ -24,7 +24,7 @@ query {

==>

Document(OperationDefinition(OperationType,SelectionSet(Selection(Field(Name,SelectionSet(Selection(Field(Name))))))))
Document(OperationDefinition(OperationType,SelectionSet("{",Selection(Field(FieldName,SelectionSet("{",Selection(Field(FieldName)),"}"))),"}")))

# Query with argument

Expand All @@ -39,7 +39,7 @@ Document(OperationDefinition(OperationType,SelectionSet(Selection(Field(Name,Sel

Document(
OperationDefinition(
SelectionSet(Selection(Field(Name,Arguments(Argument(Name,IntValue)),SelectionSet(Selection(Field(Name)),Selection(Field(Name))))))
SelectionSet("{",Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,IntValue),")"),SelectionSet("{",Selection(Field(FieldName)),Selection(Field(FieldName)),"}"))),"}")
)
)

Expand All @@ -61,23 +61,7 @@ Document(

==>

Document(
OperationDefinition(
SelectionSet(
Selection(Field(Name,Arguments(Argument(Name,StringValue)),SelectionSet(
Selection(Field(Name)),
Selection(Field(Name,SelectionSet(
Selection(Field(Name)),
Selection(Field(Name,SelectionSet(
Selection(Field(Name,SelectionSet(
Selection(Field(Name)),
))),
))),
))),
))),
)
)
)
Document(OperationDefinition(SelectionSet("{",Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,StringValue),")"),SelectionSet("{",Selection(Field(FieldName)),Selection(Field(FieldName,SelectionSet("{",Selection(Field(FieldName)),Selection(Field(FieldName,SelectionSet("{",Selection(Field(FieldName,SelectionSet("{",Selection(Field(FieldName)),"}"))),"}"))),"}"))),"}"))),"}")))

# Query of fields with arguments

Expand All @@ -95,21 +79,7 @@ Document(

==>

Document(
OperationDefinition(
SelectionSet(
Selection(Field(Name,Arguments(Argument(Name,StringValue)),SelectionSet(
Selection(Field(Name)),
))),
Selection(Field(Name,Arguments(Argument(Name,FloatValue)),SelectionSet(
Selection(Field(Name)),
))),
Selection(Field(Name,Arguments(Argument(Name,EnumValue)),SelectionSet(
Selection(Field(Name)),
))),
)
)
)
Document(OperationDefinition(SelectionSet("{",Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,StringValue),")"),SelectionSet("{",Selection(Field(FieldName)),"}"))),Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,FloatValue),")"),SelectionSet("{",Selection(Field(FieldName)),"}"))),Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,EnumValue),")"),SelectionSet("{",Selection(Field(FieldName)),"}"))),"}")))

# Multiple named queries

Expand All @@ -124,21 +94,22 @@ mutation c($val: String!) {
==>

Document(
OperationDefinition(
OperationType,Name,SelectionSet(
Selection(Field(Name)),
)
),
OperationDefinition(
OperationType,Name,SelectionSet(
Selection(Field(Name)),
)
),
OperationDefinition(
OperationType,Name,VariableDefinitions(VariableDefinition(Variable,NonNullType(NamedType(Name)))),SelectionSet(
Selection(Field(Name,Arguments(Argument(Name,Variable)),SelectionSet(
Selection(Field(Name)),
))),
)
)
OperationDefinition(OperationType,Name,SelectionSet("{",Selection(Field(FieldName)),"}")),
OperationDefinition(OperationType,Name,SelectionSet("{",Selection(Field(FieldName)),"}")),
OperationDefinition(OperationType,Name,VariableDefinitions("(",VariableDefinition(Variable,NonNullType(NamedType(Name))),")"),SelectionSet("{",Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,Variable),")"),SelectionSet("{",Selection(Field(FieldName)),"}"))),"}"))
)

# Query with a `query` field

{
other
query {
inner
}
}

==>

Document(
OperationDefinition(SelectionSet("{",Selection(Field(FieldName)),Selection(Field(FieldName,SelectionSet("{",Selection(Field(FieldName)),"}"))),"}"))
)
33 changes: 33 additions & 0 deletions packages/cm6-graphql/__tests__/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { graphqlLanguage } from '../dist/index.js';
import { fileTests } from '@lezer/generator/dist/test';

import * as fs from 'fs';
import * as path from 'path';

// because of the babel transformations, __dirname is the package root (cm6-graphql)
const caseDir = path.resolve(path.dirname(__dirname), '__tests__');

describe('codemirror 6 language', () => {
for (const file of fs.readdirSync(caseDir)) {
if (!/\.txt$/.test(file)) {
continue;
}

const describeName = /^[^.]*/.exec(file)![0];
describe(`${describeName}`, () => {
for (const { name, run } of fileTests(
fs.readFileSync(path.join(caseDir, file), 'utf8'),
file,
)) {
it(`${name}`, () => {
try {
run(graphqlLanguage.parser);
} catch (err) {
require('console').log(name, err);
throw err;
}
});
}
});
}
});
26 changes: 0 additions & 26 deletions packages/cm6-graphql/__tests__/test.ts

This file was deleted.

16 changes: 8 additions & 8 deletions packages/cm6-graphql/__tests__/types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

==>

Document(OperationDefinition(SelectionSet("{",Selection(Field(Name,Arguments(Argument(Name,StringValue)))),"}")))
Document(OperationDefinition(SelectionSet("{",Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,StringValue),")"))),"}")))

# Enum

{ test(v1: ABC) }

==>

Document(OperationDefinition(SelectionSet("{",Selection(Field(Name,Arguments(Argument(Name,EnumValue)))),"}")))
Document(OperationDefinition(SelectionSet("{",Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,EnumValue),")"))),"}")))

# Numbers

Expand All @@ -23,9 +23,9 @@ Document(OperationDefinition(SelectionSet("{",Selection(Field(Name,Arguments(Arg
==>

Document(
OperationDefinition(SelectionSet("{",Selection(Field(Name,Arguments(Argument(Name,IntValue)))),"}")),
OperationDefinition(SelectionSet("{",Selection(Field(Name,Arguments(Argument(Name,FloatValue)))),"}")),
OperationDefinition(SelectionSet("{",Selection(Field(Name,Arguments(Argument(Name,FloatValue)))),"}"))
OperationDefinition(SelectionSet("{",Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,IntValue),")"))),"}")),
OperationDefinition(SelectionSet("{",Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,FloatValue),")"))),"}")),
OperationDefinition(SelectionSet("{",Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,FloatValue),")"))),"}"))
)

# List
Expand All @@ -37,7 +37,7 @@ Document(
==>

Document(
OperationDefinition(SelectionSet("{",Selection(Field(Name,Arguments(Argument(Name,ListValue)))),"}")),
OperationDefinition(SelectionSet("{",Selection(Field(Name,Arguments(Argument(Name,ListValue(StringValue,StringValue))))),"}")),
OperationDefinition(SelectionSet("{",Selection(Field(Name,Arguments(Argument(Name,ListValue(StringValue,EnumValue,IntValue,FloatValue,BooleanValue,NullValue))))),"}"))
OperationDefinition(SelectionSet("{",Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,ListValue("[","]")),")"))),"}")),
OperationDefinition(SelectionSet("{",Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,ListValue("[",StringValue,StringValue,"]")),")"))),"}")),
OperationDefinition(SelectionSet("{",Selection(Field(FieldName,Arguments("(",Argument(ArgumentAttributeName,ListValue("[",StringValue,EnumValue,IntValue,FloatValue,BooleanValue,NullValue,"]")),")"))),"}"))
)
1 change: 1 addition & 0 deletions packages/cm6-graphql/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ const base = require('../../jest.config.base')(__dirname);

module.exports = {
...base,
transformIgnorePatterns: ['/node_modules/(?!@lezer)'],
};
5 changes: 3 additions & 2 deletions packages/cm6-graphql/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "cm6-graphql",
"version": "0.0.2",
"description": "GraphQL language support for CodeMirror",
"description": "GraphQL language support for CodeMirror 6",
"scripts": {
"prepare": "cm-buildhelper src/index.ts"
"build": "cm-buildhelper src/index.ts",
"prepare": "yarn build"
},
"main": "dist/index.cjs",
"module": "dist/index.js",
Expand Down
13 changes: 0 additions & 13 deletions packages/cm6-graphql/rollup.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/cm6-graphql/src/syntax.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ scopedBraces<expr> { !vDef "{" expr "}" }
// keywords
kw<term> { @specialize[@name={term}]<name, term> }

operation<term> { @specialize<name, term> }
operation<term> { @extend<name, term> }

ScalarKeyword { kw<"scalar"> }
TypeKeyword { kw<"type"> }
Expand Down
3 changes: 2 additions & 1 deletion packages/cm6-graphql/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"moduleResolution": "node",
"outDir": "dist"
},
"include": ["src/*.ts"],
"include": ["src", "__tests__"],
"exclude": ["**/__tests__/**", "**/dist/**.*"],
"references": [
{
"path": "../graphql-language-service"
Expand Down
Loading

0 comments on commit 5f276c4

Please sign in to comment.