Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cm6-graphql): Fix query token used as field name #2995

Merged
merged 6 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed this issue upstream, so this should no longer be needed - the cm6-graphql tsconfig for esm was missing a references entry for graphql-language-service. Project references ignores package.json on purpose, and each tsconfig needs to be taught about it's dependents.=

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cm6-graphql doesn't build with tsc though. It uses a custom build tool. Does that change anything?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works for now, this all needs an overhaul! fwiw, wsrun package has a flag to run a script (like build) automatically in order of dependencies

"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