@luvio/graphql-parser 0.62.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 (42) hide show
  1. package/babel.config.js +1 -0
  2. package/dist/argument-node.d.ts +4 -0
  3. package/dist/ast.d.ts +95 -0
  4. package/dist/constants.d.ts +12 -0
  5. package/dist/directive-node.d.ts +5 -0
  6. package/dist/document.d.ts +3 -0
  7. package/dist/field-node.d.ts +4 -0
  8. package/dist/fragment-spread-node.d.ts +4 -0
  9. package/dist/fragment.d.ts +3 -0
  10. package/dist/inline-fragment-node.d.ts +4 -0
  11. package/dist/luvioGraphqlParser.js +3887 -0
  12. package/dist/main.d.ts +4 -0
  13. package/dist/operation/index.d.ts +3 -0
  14. package/dist/operation/query/index.d.ts +6 -0
  15. package/dist/type-node.d.ts +3 -0
  16. package/dist/value-node.d.ts +4 -0
  17. package/dist/variable-definition.d.ts +4 -0
  18. package/dist/visitor.d.ts +4 -0
  19. package/jest.config.js +8 -0
  20. package/package.json +19 -0
  21. package/rollup.config.js +19 -0
  22. package/scripts/cli.mjs +18 -0
  23. package/src/__tests__/ast.spec.ts +109 -0
  24. package/src/__tests__/main.spec.ts +600 -0
  25. package/src/__tests__/type-node.spec.ts +82 -0
  26. package/src/argument-node.ts +18 -0
  27. package/src/ast.ts +200 -0
  28. package/src/constants.ts +14 -0
  29. package/src/directive-node.ts +36 -0
  30. package/src/document.ts +33 -0
  31. package/src/field-node.ts +72 -0
  32. package/src/fragment-spread-node.ts +28 -0
  33. package/src/fragment.ts +46 -0
  34. package/src/inline-fragment-node.ts +31 -0
  35. package/src/main.ts +58 -0
  36. package/src/operation/index.ts +12 -0
  37. package/src/operation/query/index.ts +78 -0
  38. package/src/type-node.ts +39 -0
  39. package/src/value-node.ts +71 -0
  40. package/src/variable-definition.ts +37 -0
  41. package/src/visitor.ts +62 -0
  42. package/tsconfig.json +9 -0
package/dist/main.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { BooleanValueNode, FloatValueNode, IntValueNode, StringValueNode } from 'graphql/language';
2
+ import { LuvioDocumentNode, LuvioArgumentNode, LuvioDefinitionNode, LuvioObjectValueNode, LuvioOperationDefinitionNode, LuvioSelectionCustomFieldNode, LuvioSelectionNode, LuvioSelectionObjectFieldNode, LuvioSelectionScalarFieldNode, LuvioValueNode, LuvioFieldNode, LuvioVariableDefinitionNode, LuvioVariableNode, LuvioNamedTypeNode, LuvioListTypeNode, LuvioListValueNode, LuvioTypeNode } from './ast';
3
+ export declare function parseAndVisit(source: string): LuvioDocumentNode;
4
+ export { BooleanValueNode, FloatValueNode, IntValueNode, StringValueNode, LuvioDocumentNode, LuvioArgumentNode, LuvioDefinitionNode, LuvioObjectValueNode, LuvioOperationDefinitionNode, LuvioSelectionCustomFieldNode, LuvioSelectionNode, LuvioSelectionObjectFieldNode, LuvioSelectionScalarFieldNode, LuvioValueNode, LuvioFieldNode, LuvioVariableDefinitionNode, LuvioVariableNode, LuvioNamedTypeNode, LuvioListTypeNode, LuvioListValueNode, LuvioTypeNode, };
@@ -0,0 +1,3 @@
1
+ import { OperationDefinitionNode } from 'graphql/language';
2
+ import { LuvioOperationDefinitionNode } from '../ast';
3
+ export declare function transform(node: OperationDefinitionNode): LuvioOperationDefinitionNode;
@@ -0,0 +1,6 @@
1
+ import { OperationDefinitionNode } from 'graphql/language';
2
+ import { LuvioOperationDefinitionNode } from '../../ast';
3
+ export interface TransformState {
4
+ variablesUsed: Record<string, true>;
5
+ }
6
+ export declare function transform(node: OperationDefinitionNode): LuvioOperationDefinitionNode;
@@ -0,0 +1,3 @@
1
+ import { TypeNode } from 'graphql/language';
2
+ import { LuvioTypeNode } from './ast';
3
+ export declare function transform(node: TypeNode): LuvioTypeNode;
@@ -0,0 +1,4 @@
1
+ import { ValueNode } from 'graphql/language';
2
+ import { LuvioValueNode } from './ast';
3
+ import { TransformState } from './operation/query';
4
+ export declare function transform(node: ValueNode, transformState: TransformState): LuvioValueNode;
@@ -0,0 +1,4 @@
1
+ import { VariableDefinitionNode } from 'graphql/language';
2
+ import { LuvioVariableDefinitionNode } from './ast';
3
+ import { TransformState } from './operation/query';
4
+ export declare function transform(variableDefinitions: VariableDefinitionNode, transformState: TransformState): LuvioVariableDefinitionNode;
@@ -0,0 +1,4 @@
1
+ import { ASTNode } from 'graphql/language';
2
+ import { LuvioSelectionNode } from './ast';
3
+ import { TransformState } from './operation/query';
4
+ export declare function selectionSetVisitor(ast: ASTNode, luvioSelectionPath: LuvioSelectionNode[], transformState: TransformState): void;
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ const baseConfig = require('../../../scripts/jest/base.config');
2
+
3
+ module.exports = {
4
+ ...baseConfig,
5
+
6
+ displayName: '@luvio/graphql-parser',
7
+ roots: ['<rootDir>/src'],
8
+ };
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@luvio/graphql-parser",
3
+ "version": "0.62.2",
4
+ "description": "GraphQL parser for LDS GraphQL adapter",
5
+ "main": "dist/luvioGraphqlParser.js",
6
+ "module": "true",
7
+ "types": "dist/main.d.ts",
8
+ "license": "MIT",
9
+ "scripts": {
10
+ "clean": "rm -rf dist",
11
+ "build": "rollup --config rollup.config.js",
12
+ "parse": "node ./scripts/cli.mjs",
13
+ "test:unit": "jest",
14
+ "test:debug": "node --inspect-brk ../../node_modules/.bin/jest --runInBand"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ import resolve from 'rollup-plugin-node-resolve';
2
+ import typescript from 'rollup-plugin-typescript2';
3
+
4
+ const luvioGraphqlParserRollupConfig = {
5
+ input: './src/main.ts',
6
+ output: {
7
+ file: 'dist/luvioGraphqlParser.js',
8
+ format: 'cjs',
9
+ },
10
+
11
+ plugins: [
12
+ resolve(),
13
+ typescript({
14
+ clean: true,
15
+ }),
16
+ ],
17
+ };
18
+
19
+ export default luvioGraphqlParserRollupConfig;
@@ -0,0 +1,18 @@
1
+ import parseAndVisit from '../dist/luvioGraphqlParser.mjs';
2
+ import { readFileSync, existsSync } from 'fs';
3
+ import { resolve as resolvePath } from 'path';
4
+
5
+ const path = process.argv[2];
6
+ if (path === undefined) {
7
+ throw new Error(`Invalid path "${path}". Usage: "yarn parse PATH_TO_GQL_QUERY.graphql)"`);
8
+ }
9
+
10
+ if (existsSync(path) === false) {
11
+ throw new Error(`Invalid file "${path}", "${path}" does not exist`);
12
+ }
13
+
14
+ const file = readFileSync(resolvePath(path)).toString();
15
+
16
+ const str = parseAndVisit(file);
17
+
18
+ console.log(JSON.stringify(str, null, 2));
@@ -0,0 +1,109 @@
1
+ import {
2
+ isOperationDefinitionNode,
3
+ isFragmentDefinitionNode,
4
+ isNamedTypeNode,
5
+ isListTypeNode,
6
+ isNonNullTypeNode,
7
+ } from '../ast';
8
+
9
+ describe('Luvio GraphQL AST', () => {
10
+ describe('utility functions', () => {
11
+ it('isOperationDefinitionNode returns true if input is GrahpQL OperationDefinitionNode', () => {
12
+ const target = isOperationDefinitionNode({
13
+ kind: 'OperationDefinition',
14
+ operation: 'query',
15
+ selectionSet: {
16
+ kind: 'SelectionSet',
17
+ selections: [],
18
+ },
19
+ });
20
+ expect(target).toBe(true);
21
+ });
22
+
23
+ it('isOperationDefinitionNode returns false if input is not GrahpQL OperationDefinitionNode', () => {
24
+ const target = isOperationDefinitionNode({
25
+ kind: 'FragmentDefinition',
26
+ name: { kind: 'Name', value: 'test' },
27
+ typeCondition: {
28
+ kind: 'NamedType',
29
+ name: { kind: 'Name', value: 'testType' },
30
+ },
31
+ selectionSet: {
32
+ kind: 'SelectionSet',
33
+ selections: [],
34
+ },
35
+ });
36
+ expect(target).toBe(false);
37
+ });
38
+
39
+ it('isFragmentDefinitionNode returns true if input is GrahpQL FragmentDefinitionNode', () => {
40
+ const target = isFragmentDefinitionNode({
41
+ kind: 'FragmentDefinition',
42
+ name: { kind: 'Name', value: 'test' },
43
+ typeCondition: {
44
+ kind: 'NamedType',
45
+ name: { kind: 'Name', value: 'testType' },
46
+ },
47
+ selectionSet: {
48
+ kind: 'SelectionSet',
49
+ selections: [],
50
+ },
51
+ });
52
+ expect(target).toBe(true);
53
+ });
54
+
55
+ it('isFragmentDefinitionNode returns false if input is not GrahpQL FragmentDefinitionNode', () => {
56
+ const target = isFragmentDefinitionNode({
57
+ kind: 'OperationDefinition',
58
+ operation: 'query',
59
+ selectionSet: {
60
+ kind: 'SelectionSet',
61
+ selections: [],
62
+ },
63
+ });
64
+ expect(target).toBe(false);
65
+ });
66
+
67
+ it('isNamedTypeNode returns true if input is GraphQL NamedTypeNode', () => {
68
+ expect(
69
+ isNamedTypeNode({
70
+ kind: 'NamedType',
71
+ name: {
72
+ kind: 'Name',
73
+ value: 'test',
74
+ },
75
+ })
76
+ ).toBe(true);
77
+ });
78
+
79
+ it('isListTypeNode returns true if input is GraphQL ListTypeNode', () => {
80
+ expect(
81
+ isListTypeNode({
82
+ kind: 'ListType',
83
+ type: {
84
+ kind: 'NamedType',
85
+ name: {
86
+ kind: 'Name',
87
+ value: 'test',
88
+ },
89
+ },
90
+ })
91
+ ).toBe(true);
92
+ });
93
+
94
+ it('isNonNullTypeNode returns true if input is Graphql NonNullTypeNode', () => {
95
+ expect(
96
+ isNonNullTypeNode({
97
+ kind: 'NonNullType',
98
+ type: {
99
+ kind: 'NamedType',
100
+ name: {
101
+ kind: 'Name',
102
+ value: 'test',
103
+ },
104
+ },
105
+ })
106
+ ).toBe(true);
107
+ });
108
+ });
109
+ });