@luvio/graphql-parser 0.126.0 → 0.126.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/argument-node.d.ts +4 -0
  2. package/dist/ast.d.ts +95 -0
  3. package/dist/constants.d.ts +12 -0
  4. package/dist/directive-node.d.ts +5 -0
  5. package/dist/document.d.ts +3 -0
  6. package/dist/field-node.d.ts +4 -0
  7. package/dist/fragment-spread-node.d.ts +4 -0
  8. package/dist/fragment.d.ts +3 -0
  9. package/dist/gql.d.ts +51 -0
  10. package/dist/inline-fragment-node.d.ts +4 -0
  11. package/dist/luvioGraphqlParser.js +12945 -0
  12. package/dist/luvioGraphqlParser.mjs +12923 -0
  13. package/dist/main.d.ts +18 -0
  14. package/dist/metaschema.d.ts +10 -0
  15. package/dist/operation/index.d.ts +3 -0
  16. package/dist/operation/query/index.d.ts +6 -0
  17. package/dist/type-node.d.ts +3 -0
  18. package/dist/util/language.d.ts +9 -0
  19. package/dist/value-node.d.ts +4 -0
  20. package/dist/variable-definition.d.ts +4 -0
  21. package/dist/visitor.d.ts +4 -0
  22. package/package.json +4 -1
  23. package/babel.config.js +0 -1
  24. package/jest.config.js +0 -8
  25. package/project.json +0 -7
  26. package/rollup.config.js +0 -24
  27. package/scripts/cli.mjs +0 -18
  28. package/src/__tests__/ast.json +0 -403
  29. package/src/__tests__/ast.spec.ts +0 -109
  30. package/src/__tests__/astNoLoc.json +0 -147
  31. package/src/__tests__/gql.spec.ts +0 -665
  32. package/src/__tests__/main.spec.ts +0 -651
  33. package/src/__tests__/metaschema.spec.ts +0 -230
  34. package/src/__tests__/type-node.spec.ts +0 -82
  35. package/src/argument-node.ts +0 -18
  36. package/src/ast.ts +0 -200
  37. package/src/constants.ts +0 -14
  38. package/src/directive-node.ts +0 -36
  39. package/src/document.ts +0 -29
  40. package/src/field-node.ts +0 -72
  41. package/src/fragment-spread-node.ts +0 -28
  42. package/src/fragment.ts +0 -46
  43. package/src/gql.ts +0 -222
  44. package/src/inline-fragment-node.ts +0 -31
  45. package/src/main.ts +0 -134
  46. package/src/metaschema.ts +0 -162
  47. package/src/operation/index.ts +0 -12
  48. package/src/operation/query/index.ts +0 -78
  49. package/src/type-node.ts +0 -40
  50. package/src/util/language.ts +0 -10
  51. package/src/value-node.ts +0 -71
  52. package/src/variable-definition.ts +0 -37
  53. package/src/visitor.ts +0 -63
  54. package/tsconfig.json +0 -9
@@ -1,78 +0,0 @@
1
- import type { OperationDefinitionNode, VariableDefinitionNode } from 'graphql/language';
2
- import type { LuvioFieldNode, LuvioOperationDefinitionNode, LuvioSelectionNode } from '../../ast';
3
- import { selectionSetVisitor } from '../../visitor';
4
- import { transform as transformVariableDefinition } from '../../variable-definition';
5
- import { transform as transformDirectiveNode } from '../../directive-node';
6
-
7
- export interface TransformState {
8
- variablesUsed: Record<string, true>;
9
- }
10
-
11
- export function transform(node: OperationDefinitionNode): LuvioOperationDefinitionNode {
12
- const queryRoot: LuvioFieldNode = {
13
- kind: 'ObjectFieldSelection',
14
- name: 'query',
15
- luvioSelections: [],
16
- };
17
- const currentNodePath: LuvioSelectionNode[] = [queryRoot];
18
-
19
- const transformState = {
20
- variablesUsed: {},
21
- };
22
- selectionSetVisitor(node, currentNodePath, transformState);
23
-
24
- const operationDefinition: LuvioOperationDefinitionNode = {
25
- kind: 'OperationDefinition',
26
- operation: 'query',
27
- luvioSelections: queryRoot.luvioSelections!,
28
- };
29
-
30
- if (node.name !== undefined) {
31
- operationDefinition.name = node.name.value;
32
- }
33
-
34
- const { variableDefinitions, directives } = node;
35
- if (variableDefinitions !== undefined && variableDefinitions.length > 0) {
36
- operationDefinition.variableDefinitions = variableDefinitions.map((variableDefinition) =>
37
- transformVariableDefinition(variableDefinition, transformState)
38
- );
39
- }
40
-
41
- if (directives !== undefined && directives.length > 0) {
42
- operationDefinition.directives = directives.map((node) =>
43
- transformDirectiveNode(node, transformState)
44
- );
45
- }
46
-
47
- validateVariables(variableDefinitions, transformState);
48
-
49
- return operationDefinition;
50
- }
51
-
52
- function validateVariables(
53
- variableDefinitions: readonly VariableDefinitionNode[] | undefined,
54
- transformState: TransformState
55
- ) {
56
- const variablesDefined: Record<string, true> = {};
57
-
58
- if (variableDefinitions !== undefined) {
59
- for (let i = 0, len = variableDefinitions.length; i < len; i++) {
60
- const definedVariableName = variableDefinitions[i].variable.name.value;
61
- variablesDefined[definedVariableName] = true;
62
- if (transformState.variablesUsed[definedVariableName] === undefined) {
63
- if (process.env.NODE_ENV !== 'production') {
64
- throw new Error(`Variable $${definedVariableName} was defined but never used.`);
65
- }
66
- }
67
- }
68
- }
69
-
70
- const usedVariableKeys = Object.keys(transformState.variablesUsed);
71
- for (let i = 0, len = usedVariableKeys.length; i < len; i++) {
72
- if (variablesDefined[usedVariableKeys[i]] !== true) {
73
- if (process.env.NODE_ENV !== 'production') {
74
- throw new Error(`Variable $${usedVariableKeys[i]} was used but never defined.`);
75
- }
76
- }
77
- }
78
- }
package/src/type-node.ts DELETED
@@ -1,40 +0,0 @@
1
- import type { TypeNode } from 'graphql/language';
2
- import type { LuvioTypeNode } from './ast';
3
- import { isListTypeNode, isNamedTypeNode, isNonNullTypeNode } from './ast';
4
- import { NODE_KIND_NAMED_TYPE, NODE_KIND_LIST_TYPE, NODE_KIND_NON_NULL_TYPE } from './constants';
5
-
6
- export function transform(node: TypeNode): LuvioTypeNode {
7
- if (isNamedTypeNode(node)) {
8
- return {
9
- kind: NODE_KIND_NAMED_TYPE,
10
- name: node.name.value,
11
- };
12
- } else if (isListTypeNode(node)) {
13
- return {
14
- kind: NODE_KIND_LIST_TYPE,
15
- type: transform(node.type),
16
- };
17
- } else if (isNonNullTypeNode(node)) {
18
- if (isNamedTypeNode(node.type)) {
19
- return {
20
- kind: NODE_KIND_NON_NULL_TYPE,
21
- type: {
22
- kind: NODE_KIND_NAMED_TYPE,
23
- name: node.type.name.value,
24
- },
25
- };
26
- } else if (isListTypeNode(node.type)) {
27
- return {
28
- kind: NODE_KIND_NON_NULL_TYPE,
29
- type: {
30
- kind: NODE_KIND_LIST_TYPE,
31
- type: transform(node.type.type),
32
- },
33
- };
34
- } else {
35
- throw new Error('Unsupported NonNullTypeNode');
36
- }
37
- } else {
38
- throw new Error('Unsupported TypeNode');
39
- }
40
- }
@@ -1,10 +0,0 @@
1
- const { isArray } = Array;
2
- const { create, keys } = Object;
3
-
4
- export {
5
- // Array
6
- isArray as ArrayIsArray,
7
- // Object
8
- keys as ObjectKeys,
9
- create as ObjectCreate,
10
- };
package/src/value-node.ts DELETED
@@ -1,71 +0,0 @@
1
- import type { ValueNode } from 'graphql/language';
2
- import type { LuvioValueNode } from './ast';
3
- import type { TransformState } from './operation/query';
4
-
5
- export function transform(node: ValueNode, transformState: TransformState): LuvioValueNode {
6
- switch (node.kind) {
7
- case 'Variable':
8
- transformState.variablesUsed[node.name.value] = true;
9
- return {
10
- kind: 'Variable',
11
- name: node.name.value,
12
- };
13
- case 'IntValue':
14
- return {
15
- kind: 'IntValue',
16
- value: node.value,
17
- };
18
- case 'FloatValue':
19
- return {
20
- kind: 'FloatValue',
21
- value: node.value,
22
- };
23
- case 'StringValue':
24
- return {
25
- kind: 'StringValue',
26
- value: node.value,
27
- };
28
- case 'BooleanValue':
29
- return {
30
- kind: 'BooleanValue',
31
- value: node.value,
32
- };
33
- case 'EnumValue':
34
- return {
35
- kind: 'EnumValue',
36
- value: node.value,
37
- };
38
- case 'NullValue':
39
- return {
40
- kind: 'NullValue',
41
- };
42
- case 'ListValue': {
43
- const values = [];
44
- for (var index = 0; index < node.values.length; index++) {
45
- const value = transform(node.values[index], transformState);
46
- values.push(value);
47
- }
48
-
49
- return {
50
- kind: 'ListValue',
51
- values: values,
52
- };
53
- }
54
- case 'ObjectValue': {
55
- const { fields } = node;
56
- const result: { [name: string]: LuvioValueNode } = {};
57
- fields.forEach((field) => {
58
- const name = field.name.value;
59
- const value = transform(field.value, transformState);
60
- result[name] = value;
61
- });
62
-
63
- return {
64
- kind: 'ObjectValue',
65
- fields: result,
66
- };
67
- }
68
- default:
69
- throw new Error('Unsupported ValueNode kind');
70
- }
71
- }
@@ -1,37 +0,0 @@
1
- import type { VariableDefinitionNode } from 'graphql/language';
2
- import type { LuvioVariableDefinitionNode } from './ast';
3
- import type { TransformState } from './operation/query';
4
- import { transform as transformTypeNode } from './type-node';
5
- import { transform as transformValueNode } from './value-node';
6
-
7
- export function transform(
8
- variableDefinitions: VariableDefinitionNode,
9
- transformState: TransformState
10
- ): LuvioVariableDefinitionNode {
11
- const {
12
- kind,
13
- variable: {
14
- kind: variableKind,
15
- name: { value: variableName },
16
- },
17
- type,
18
- defaultValue,
19
- } = variableDefinitions;
20
- const ret: LuvioVariableDefinitionNode = {
21
- kind,
22
- variable: {
23
- kind: variableKind,
24
- name: variableName,
25
- },
26
- type: transformTypeNode(type),
27
- };
28
-
29
- if (defaultValue !== undefined) {
30
- const value = transformValueNode(defaultValue, transformState);
31
- ret.defaultValue = value;
32
- }
33
-
34
- // TODO: transform directives
35
-
36
- return ret;
37
- }
package/src/visitor.ts DELETED
@@ -1,63 +0,0 @@
1
- import type { ASTNode, ASTVisitor } from 'graphql/language';
2
- import { visit } from 'graphql/language';
3
- import type { LuvioSelectionNode } from './ast';
4
- import {
5
- NODE_KIND_CUSTOM_FIELD_SELECTION,
6
- NODE_KIND_FIELD,
7
- NODE_KIND_FRAGMENT_SPREAD,
8
- NODE_KIND_INLINE_FRAGMENT,
9
- NODE_KIND_OBJECT_FIELD_SELECTION,
10
- } from './constants';
11
- import { transform as transformFieldNode } from './field-node';
12
- import { transform as transformFragmentSpreadNode } from './fragment-spread-node';
13
- import { transform as transformInlineFragmentNode } from './inline-fragment-node';
14
- import type { TransformState } from './operation/query';
15
-
16
- export function selectionSetVisitor(
17
- ast: ASTNode,
18
- luvioSelectionPath: LuvioSelectionNode[],
19
- transformState: TransformState
20
- ): void {
21
- const visitor: ASTVisitor = {
22
- enter(node) {
23
- let selectionNode: LuvioSelectionNode | undefined;
24
- switch (node.kind) {
25
- case NODE_KIND_FIELD: {
26
- const fieldNode = transformFieldNode(node, transformState);
27
- selectionNode = fieldNode;
28
- break;
29
- }
30
- case NODE_KIND_FRAGMENT_SPREAD:
31
- selectionNode = transformFragmentSpreadNode(node, transformState);
32
- break;
33
- case NODE_KIND_INLINE_FRAGMENT:
34
- selectionNode = transformInlineFragmentNode(node, transformState);
35
- break;
36
- }
37
-
38
- if (selectionNode !== undefined) {
39
- const parentNode = luvioSelectionPath[luvioSelectionPath.length - 1];
40
- if (
41
- parentNode.kind === NODE_KIND_OBJECT_FIELD_SELECTION ||
42
- parentNode.kind === NODE_KIND_CUSTOM_FIELD_SELECTION ||
43
- parentNode.kind === NODE_KIND_INLINE_FRAGMENT
44
- ) {
45
- parentNode.luvioSelections!.push(selectionNode);
46
- }
47
-
48
- luvioSelectionPath.push(selectionNode);
49
- }
50
- },
51
- leave(node) {
52
- switch (node.kind) {
53
- case NODE_KIND_FIELD:
54
- case NODE_KIND_FRAGMENT_SPREAD:
55
- case NODE_KIND_INLINE_FRAGMENT:
56
- luvioSelectionPath.pop();
57
- break;
58
- }
59
- },
60
- };
61
-
62
- visit(ast, visitor);
63
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.json",
3
-
4
- "compilerOptions": {
5
- "outDir": "dist"
6
- },
7
-
8
- "include": ["src"]
9
- }