Skip to content

Commit 7535262

Browse files
committed
Merge branch 'master' into digits
2 parents abb60a8 + 855a6b5 commit 7535262

19 files changed

+3425
-3799
lines changed

ast/argument.go

+9
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,12 @@ func (a ArgumentsDefinition) Get(name string) *InputValueDefinition {
4343
}
4444
return nil
4545
}
46+
47+
// Names returns a slice of ArgumentsDefinition names.
48+
func (a ArgumentsDefinition) Names() []string {
49+
names := make([]string, len(a))
50+
for i, f := range a {
51+
names[i] = f.Name.Name
52+
}
53+
return names
54+
}

example/federation/integration/gateway/package-lock.json

+21-58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graphql_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5270,8 +5270,8 @@ func TestCircularFragmentMaxDepth(t *testing.T) {
52705270
}
52715271
`,
52725272
ExpectedErrors: []*gqlerrors.QueryError{{
5273-
Message: `Cannot spread fragment "X" within itself via Y.`,
5274-
Rule: "NoFragmentCycles",
5273+
Message: `Cannot spread fragment "X" within itself via "Y".`,
5274+
Rule: "NoFragmentCyclesRule",
52755275
Locations: []gqlerrors.Location{
52765276
{Line: 7, Column: 20},
52775277
{Line: 10, Column: 20},

internal/common/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func ResolveType(t ast.Type, resolver Resolver) (ast.Type, *errors.QueryError) {
5656
refT := resolver(t.Name)
5757
if refT == nil {
5858
err := errors.Errorf("Unknown type %q.", t.Name)
59-
err.Rule = "KnownTypeNames"
59+
err.Rule = "KnownTypeNamesRule"
6060
err.Locations = []errors.Location{t.Loc}
6161
return nil, err
6262
}

internal/validation/suggestion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func makeSuggestion(prefix string, options []string, input string) string {
1212
distances := make(map[string]int)
1313
for _, opt := range options {
1414
distance := levenshteinDistance(input, opt)
15-
threshold := max(len(input)/2, max(len(opt)/2, 1))
15+
threshold := max(len(input)/2, max(len(opt)/2, 2))
1616
if distance < threshold {
1717
selected = append(selected, opt)
1818
distances[opt] = distance
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# graphql-js testdata
2+
3+
Test cases are generated here by extracting them from [graphql-js] into JSON that we can use to drive Go tests.
4+
5+
## Usage
6+
7+
To update the testdata, run the following command within the `testdata` directory:
8+
9+
```sh
10+
go generate .
11+
```
12+
13+
## How it works
14+
15+
A Node.js project is used to pull in graphql-js as a dependency, and automatically patch that via `patch-package`. These
16+
patches replace the `mocha` test functions `describe`, `it`, assertions and the test `harness`. This allows the
17+
expectations to be captured, and written to a JSON file. These test cases in the JSON file are then used to drive the Go
18+
tests.
19+
20+
## Updating patches
21+
22+
With changes to [graphql-js], the patches may need to be updated. To do this, update the `graphql` dependency under
23+
`node_modules`, and sync the patches with the following command:
24+
25+
```sh
26+
npm run create-patches
27+
```
28+
29+
[graphql-js]: https://github.com/graphql/graphql-js

internal/validation/testdata/export.js

-118
This file was deleted.
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import * as fs from 'node:fs';
2+
import { createHash } from 'crypto';
3+
import { printSchema } from 'graphql/src/utilities/printSchema.js';
4+
import { schemas, testCases } from 'graphql/src/validation/__tests__/harness.js';
5+
6+
// TODO: Fix test failures.
7+
// require('graphql/src/validation/__tests__/ExecutableDefinitions-test');
8+
import 'graphql/src/validation/__tests__/FieldsOnCorrectTypeRule-test.js';
9+
import 'graphql/src/validation/__tests__/FragmentsOnCompositeTypesRule-test.js';
10+
import 'graphql/src/validation/__tests__/KnownArgumentNamesRule-test.js';
11+
import 'graphql/src/validation/__tests__/KnownDirectivesRule-test.js';
12+
import 'graphql/src/validation/__tests__/KnownFragmentNamesRule-test.js';
13+
import 'graphql/src/validation/__tests__/KnownTypeNamesRule-test.js';
14+
import 'graphql/src/validation/__tests__/LoneAnonymousOperationRule-test.js';
15+
import 'graphql/src/validation/__tests__/NoFragmentCyclesRule-test.js';
16+
import 'graphql/src/validation/__tests__/NoUndefinedVariablesRule-test.js';
17+
import 'graphql/src/validation/__tests__/NoUnusedFragmentsRule-test.js';
18+
import 'graphql/src/validation/__tests__/NoUnusedVariablesRule-test.js';
19+
import 'graphql/src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.js';
20+
import 'graphql/src/validation/__tests__/PossibleFragmentSpreadsRule-test.js';
21+
import 'graphql/src/validation/__tests__/ProvidedRequiredArgumentsRule-test.js';
22+
import 'graphql/src/validation/__tests__/ScalarLeafsRule-test.js';
23+
// TODO: Add support for subscriptions.
24+
// require('graphql/src/validation/__tests__/SingleFieldSubscriptions-test.js');
25+
import 'graphql/src/validation/__tests__/UniqueArgumentNamesRule-test.js';
26+
import 'graphql/src/validation/__tests__/UniqueDirectivesPerLocationRule-test.js';
27+
import 'graphql/src/validation/__tests__/UniqueFragmentNamesRule-test.js';
28+
import 'graphql/src/validation/__tests__/UniqueInputFieldNamesRule-test.js';
29+
import 'graphql/src/validation/__tests__/UniqueOperationNamesRule-test.js';
30+
import 'graphql/src/validation/__tests__/UniqueVariableNamesRule-test.js';
31+
// TODO: Fix test failures.
32+
// require('graphql/src/validation/__tests__/ValuesofCorrectType-test');
33+
import 'graphql/src/validation/__tests__/VariablesAreInputTypesRule-test.js';
34+
// TODO: Fix test failures.
35+
// require('graphql/src/validation/__tests__/VariablesDefaultValueAllowed-test');
36+
import 'graphql/src/validation/__tests__/VariablesInAllowedPositionRule-test.js';
37+
38+
// Schema index in the source array can be unstable, as its dependent on the order they are used in the registered test
39+
// files. The SHA256 of the schema will change if there are any changes to the content, but is a better reference than
40+
// the schema indexes all changing when a new schema is inserted.
41+
let s = schemas().map(s => {
42+
const sdl = printSchema(s)
43+
const id = createHash('sha256').update(sdl).digest('base64');
44+
const v: { id: string; sdl: string; } = {id: id, sdl: sdl};
45+
return v;
46+
});
47+
48+
const tests = testCases().map(c => {
49+
const schema = s[c.schema];
50+
return {
51+
name: c.name,
52+
rule: c.rule,
53+
schema: schema.id,
54+
query: c.query,
55+
errors: c.errors,
56+
}
57+
});
58+
59+
// Order based on the schema string to provide semi-stable ordering
60+
s = s.sort((a, b) => a.sdl.localeCompare(b.sdl));
61+
62+
let output = JSON.stringify({schemas: s, tests: tests}, null, 2)
63+
output = output.replace(/ Did you mean to use an inline fragment on [^?]*\?/g, '');
64+
// Ignore suggested types in errors, which graphql-go does not currently produce.
65+
output = output.replace(/ Did you mean \\"[A-Z].*\"\?/g, '');
66+
fs.writeFileSync("tests.json", output);

0 commit comments

Comments
 (0)