Skip to content

Commit 63ccf8a

Browse files
committed
new version with newer graphql support
1 parent f6df5a6 commit 63ccf8a

File tree

6 files changed

+36
-32
lines changed

6 files changed

+36
-32
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-js-tree",
3-
"version": "1.0.9",
3+
"version": "2.0.0",
44
"private": false,
55
"license": "MIT",
66
"description": "GraphQL Parser providing simplier structure",
@@ -39,6 +39,6 @@
3939
"typescript-transform-paths": "^3.4.6"
4040
},
4141
"dependencies": {
42-
"graphql": "15.4.0"
42+
"graphql": "^16.8.1"
4343
}
4444
}

src/GqlParser/GqlParserTreeToGql.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getValueAsGqlStringNode } from '@/GqlParser/valueNode';
33
import { Instances, TypeSystemDefinition } from '@/Models';
44
import { GqlParserTree, VariableDefinitionWithoutLoc } from '@/Models/GqlParserTree';
55
import { compileType } from '@/shared';
6+
import { Kind } from 'graphql';
67
export const parseGqlTree = (mainTree: GqlParserTree) => {
78
const generateName = (tree: GqlParserTree): string => {
89
if (tree.operation) {
@@ -65,7 +66,7 @@ export const enrichFieldNodeWithVariables = (
6566
name: a.name,
6667
node: a,
6768
value: {
68-
kind: 'Variable',
69+
kind: Kind.VARIABLE,
6970
value: VarName,
7071
},
7172
};

src/GqlParser/valueNode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ValueNodeWithoutLoc } from '@/Models/GqlParserTree';
2-
import { ValueNode } from 'graphql';
2+
import { Kind, ValueNode } from 'graphql';
33

44
export const getValueAsGqlStringNode = (v: ValueNodeWithoutLoc): string => {
55
if (v.kind === 'ListValue') {
@@ -41,7 +41,7 @@ export const getValueWithoutLoc = (v: ValueNode): ValueNodeWithoutLoc => {
4141
return {
4242
kind: v.kind,
4343
fields: v.fields.map((f) => ({
44-
kind: 'ObjectField',
44+
kind: Kind.OBJECT_FIELD,
4545
name: f.name.value,
4646
value: getValueWithoutLoc(f.value),
4747
})),

src/__tests__/GqlParser/GqlParserTreeToGql.spec.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { OperationType, TypeDefinition } from '@/Models';
99
import { GqlParserTree } from '@/Models/GqlParserTree';
1010
import { createPlainField, createPlainInputValue, createRootField, createTypeNameField } from '@/shared';
1111
import { expectTrimmedEqual } from '@/__tests__/TestUtils';
12+
import { Kind } from 'graphql';
1213

1314
const mockSchema = `
1415
type Query {
@@ -113,29 +114,29 @@ describe('Test generation of gql strings from the GqlParserTree', () => {
113114
name: 'maxValue',
114115
node: queryNode.args[0].args[0],
115116
value: {
116-
kind: 'IntValue',
117+
kind: Kind.INT,
117118
value: '100',
118119
},
119120
},
120121
{
121122
name: 'score',
122123
node: queryNode.args[0].args[1],
123124
value: {
124-
kind: 'ObjectValue',
125+
kind: Kind.OBJECT,
125126
fields: [
126127
{
127-
kind: 'ObjectField',
128+
kind: Kind.OBJECT_FIELD,
128129
name: 'value',
129130
value: {
130-
kind: 'FloatValue',
131+
kind: Kind.FLOAT,
131132
value: '1.0',
132133
},
133134
},
134135
{
135-
kind: 'ObjectField',
136+
kind: Kind.OBJECT_FIELD,
136137
name: 'name',
137138
value: {
138-
kind: 'StringValue',
139+
kind: Kind.STRING,
139140
value: 'Hello',
140141
},
141142
},

src/__tests__/GqlParser/index.spec.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { parseGql } from '@/GqlParser';
22
import { OperationType, TypeDefinition } from '@/Models';
33
import { GqlParserTree } from '@/Models/GqlParserTree';
44
import { createPlainField, createPlainInputValue, createRootField, createTypeNameField } from '@/shared';
5+
import { Kind } from 'graphql';
56

67
const mockSchema = `
78
type Query {
@@ -107,29 +108,29 @@ describe('Test generation of GqlParserTrees from gql', () => {
107108
name: 'maxValue',
108109
node: queryNode.args[0].args[0],
109110
value: {
110-
kind: 'IntValue',
111+
kind: Kind.INT,
111112
value: '100',
112113
},
113114
},
114115
{
115116
name: 'score',
116117
node: queryNode.args[0].args[1],
117118
value: {
118-
kind: 'ObjectValue',
119+
kind: Kind.OBJECT,
119120
fields: [
120121
{
121-
kind: 'ObjectField',
122+
kind: Kind.OBJECT_FIELD,
122123
name: 'value',
123124
value: {
124-
kind: 'FloatValue',
125+
kind: Kind.FLOAT,
125126
value: '1.0',
126127
},
127128
},
128129
{
129-
kind: 'ObjectField',
130+
kind: Kind.OBJECT_FIELD,
130131
name: 'name',
131132
value: {
132-
kind: 'StringValue',
133+
kind: Kind.STRING,
133134
value: 'Hello',
134135
},
135136
},
@@ -173,15 +174,15 @@ describe('Test generation of GqlParserTrees from gql', () => {
173174
name: 'maxValue',
174175
node: queryNode.args[0].args[0],
175176
value: {
176-
kind: 'Variable',
177+
kind: Kind.VARIABLE,
177178
value: 'maxValue',
178179
},
179180
},
180181
{
181182
name: 'score',
182183
node: queryNode.args[0].args[1],
183184
value: {
184-
kind: 'Variable',
185+
kind: Kind.VARIABLE,
185186
value: 'score',
186187
},
187188
},

src/__tests__/GqlParser/valueNode.spec.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,52 @@
11
import { getValueAsGqlStringNode } from '@/GqlParser/valueNode';
22
import { expectTrimmedEqual } from '@/__tests__/TestUtils';
3+
import { Kind } from 'graphql';
34

45
describe('Test generation of value strings from the GqlParserTree', () => {
56
it('Generates Correct Variable Value', () => {
6-
const strValue = getValueAsGqlStringNode({ kind: 'Variable', value: 'Hello' });
7+
const strValue = getValueAsGqlStringNode({ kind: Kind.VARIABLE, value: 'Hello' });
78
expect(strValue).toEqual(`$Hello`);
89
});
910
it('Generates Correct String Value', () => {
10-
const strValue = getValueAsGqlStringNode({ kind: 'StringValue', value: 'Hello' });
11+
const strValue = getValueAsGqlStringNode({ kind: Kind.STRING, value: 'Hello' });
1112
expect(strValue).toEqual(`"Hello"`);
1213
});
1314
it('Generates Correct Int Value', () => {
14-
const strValue = getValueAsGqlStringNode({ kind: 'IntValue', value: '100' });
15+
const strValue = getValueAsGqlStringNode({ kind: Kind.INT, value: '100' });
1516
expect(strValue).toEqual(`100`);
1617
});
1718
it('Generates Correct Float Value', () => {
18-
const strValue = getValueAsGqlStringNode({ kind: 'FloatValue', value: '100.0' });
19+
const strValue = getValueAsGqlStringNode({ kind: Kind.FLOAT, value: '100.0' });
1920
expect(strValue).toEqual(`100.0`);
2021
});
2122
it('Generates Correct Boolean Value', () => {
22-
const strValue = getValueAsGqlStringNode({ kind: 'BooleanValue', value: false });
23+
const strValue = getValueAsGqlStringNode({ kind: Kind.BOOLEAN, value: false });
2324
expect(strValue).toEqual(`false`);
2425
});
2526
it('Generates Correct Enum Value', () => {
26-
const strValue = getValueAsGqlStringNode({ kind: 'EnumValue', value: 'HELLO' });
27+
const strValue = getValueAsGqlStringNode({ kind: Kind.ENUM, value: 'HELLO' });
2728
expect(strValue).toEqual(`HELLO`);
2829
});
2930
it('Generates Correct Null Value', () => {
30-
const strValue = getValueAsGqlStringNode({ kind: 'NullValue', value: null });
31+
const strValue = getValueAsGqlStringNode({ kind: Kind.NULL, value: null });
3132
expect(strValue).toEqual(`null`);
3233
});
3334
it('Generates Correct List Value', () => {
3435
const strValue = getValueAsGqlStringNode({
35-
kind: 'ListValue',
36+
kind: Kind.LIST,
3637
values: [
37-
{ kind: 'StringValue', value: 'Hello' },
38-
{ kind: 'StringValue', value: 'World' },
38+
{ kind: Kind.STRING, value: 'Hello' },
39+
{ kind: Kind.STRING, value: 'World' },
3940
],
4041
});
4142
expectTrimmedEqual(strValue, `["Hello", "World"]`);
4243
});
4344
it('Generates Correct Object Value', () => {
4445
const strValue = getValueAsGqlStringNode({
45-
kind: 'ObjectValue',
46+
kind: Kind.OBJECT,
4647
fields: [
47-
{ kind: 'ObjectField', name: 'word', value: { kind: 'StringValue', value: 'Hello' } },
48-
{ kind: 'ObjectField', name: 'word2', value: { kind: 'StringValue', value: 'Hello' } },
48+
{ kind: Kind.OBJECT_FIELD, name: 'word', value: { kind: Kind.STRING, value: 'Hello' } },
49+
{ kind: Kind.OBJECT_FIELD, name: 'word2', value: { kind: Kind.STRING, value: 'Hello' } },
4950
],
5051
});
5152
expectTrimmedEqual(

0 commit comments

Comments
 (0)