@luvio/graphql-parser 0.73.3 → 0.73.8
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.
- package/dist/argument-node.d.ts +3 -3
- package/dist/ast.d.ts +1 -1
- package/dist/directive-node.d.ts +3 -3
- package/dist/document.d.ts +2 -2
- package/dist/field-node.d.ts +3 -3
- package/dist/fragment-spread-node.d.ts +3 -3
- package/dist/fragment.d.ts +2 -2
- package/dist/inline-fragment-node.d.ts +3 -3
- package/dist/luvio-schema.d.ts +11 -0
- package/dist/luvioGraphqlParser.js +7073 -211
- package/dist/luvioGraphqlParser.mjs +10711 -0
- package/dist/main.d.ts +6 -0
- package/dist/operation/index.d.ts +2 -2
- package/dist/operation/query/index.d.ts +2 -2
- package/dist/type-node.d.ts +2 -2
- package/dist/value-node.d.ts +3 -3
- package/dist/variable-definition.d.ts +3 -3
- package/dist/visitor.d.ts +3 -3
- package/package.json +17 -5
- package/rollup.config.js +10 -5
- package/src/__tests__/__snapshots__/schema.spec.ts.snap +2132 -0
- package/src/__tests__/data/github.graphql +48492 -0
- package/src/__tests__/data/swapi.graphql +1166 -0
- package/src/__tests__/schema.spec.ts +21 -0
- package/src/argument-node.ts +3 -3
- package/src/ast.ts +1 -1
- package/src/directive-node.ts +3 -3
- package/src/document.ts +3 -7
- package/src/field-node.ts +3 -3
- package/src/fragment-spread-node.ts +3 -3
- package/src/fragment.ts +2 -2
- package/src/inline-fragment-node.ts +3 -3
- package/src/luvio-schema.ts +18 -0
- package/src/main.ts +19 -2
- package/src/operation/index.ts +2 -2
- package/src/operation/query/index.ts +2 -2
- package/src/type-node.ts +3 -2
- package/src/value-node.ts +3 -3
- package/src/variable-definition.ts +3 -3
- package/src/visitor.ts +4 -3
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { parseLuvioSchema } from '../main';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
function readSchemaAsString(fileName: string) {
|
|
6
|
+
const fullPath = path.join(__dirname, 'data', fileName);
|
|
7
|
+
const buffer = readFileSync(fullPath);
|
|
8
|
+
return buffer.toString();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('Luvio GraphQL Schema Parsing', () => {
|
|
12
|
+
it('default implementation can parse github api', () => {
|
|
13
|
+
const schema = parseLuvioSchema(readSchemaAsString('github.graphql'), 'githubSchema');
|
|
14
|
+
expect(schema).toMatchSnapshot();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('default implementation can parse star wars api', () => {
|
|
18
|
+
const schema = parseLuvioSchema(readSchemaAsString('swapi.graphql'), 'swapiSchema');
|
|
19
|
+
expect(schema).toMatchSnapshot();
|
|
20
|
+
});
|
|
21
|
+
});
|
package/src/argument-node.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ArgumentNode } from 'graphql/language';
|
|
2
|
-
import { LuvioArgumentNode } from './ast';
|
|
3
|
-
import { TransformState } from './operation/query';
|
|
1
|
+
import type { ArgumentNode } from 'graphql/language';
|
|
2
|
+
import type { LuvioArgumentNode } from './ast';
|
|
3
|
+
import type { TransformState } from './operation/query';
|
|
4
4
|
import { transform as transformValueNode } from './value-node';
|
|
5
5
|
|
|
6
6
|
export function transform(node: ArgumentNode, transformState: TransformState): LuvioArgumentNode {
|
package/src/ast.ts
CHANGED
package/src/directive-node.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DirectiveNode } from 'graphql/language';
|
|
2
|
-
import { LuvioArgumentNode, LuvioDirectiveNode } from './ast';
|
|
1
|
+
import type { DirectiveNode } from 'graphql/language';
|
|
2
|
+
import type { LuvioArgumentNode, LuvioDirectiveNode } from './ast';
|
|
3
3
|
import { transform as transformArgumentNode } from './argument-node';
|
|
4
4
|
import { CUSTOM_DIRECTIVE_CONNECTION, CUSTOM_DIRECTIVE_RESOURCE } from './constants';
|
|
5
|
-
import { TransformState } from './operation/query';
|
|
5
|
+
import type { TransformState } from './operation/query';
|
|
6
6
|
|
|
7
7
|
export function transform(node: DirectiveNode, transformState: TransformState): LuvioDirectiveNode {
|
|
8
8
|
const {
|
package/src/document.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { DocumentNode } from 'graphql/language';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
LuvioDefinitionNode,
|
|
5
|
-
isOperationDefinitionNode,
|
|
6
|
-
isFragmentDefinitionNode,
|
|
7
|
-
} from './ast';
|
|
1
|
+
import type { DocumentNode } from 'graphql/language';
|
|
2
|
+
import type { LuvioDocumentNode, LuvioDefinitionNode } from './ast';
|
|
3
|
+
import { isOperationDefinitionNode, isFragmentDefinitionNode } from './ast';
|
|
8
4
|
import { transform as operationDefinitionTransform } from './operation';
|
|
9
5
|
import { transform as fragmentDefinitionTransform } from './fragment';
|
|
10
6
|
|
package/src/field-node.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FieldNode, StringValueNode } from 'graphql/language';
|
|
1
|
+
import type { FieldNode, StringValueNode } from 'graphql/language';
|
|
2
2
|
import { transform as transformArgumentNode } from './argument-node';
|
|
3
|
-
import { LuvioArgumentNode, LuvioFieldNode } from './ast';
|
|
3
|
+
import type { LuvioArgumentNode, LuvioFieldNode } from './ast';
|
|
4
4
|
import {
|
|
5
5
|
CUSTOM_DIRECTIVE_CONNECTION,
|
|
6
6
|
CUSTOM_DIRECTIVE_RESOURCE,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
NODE_TYPE_CONNECTION,
|
|
11
11
|
} from './constants';
|
|
12
12
|
import { isCustomDirective, transform as transformDirectiveNode } from './directive-node';
|
|
13
|
-
import { TransformState } from './operation/query';
|
|
13
|
+
import type { TransformState } from './operation/query';
|
|
14
14
|
|
|
15
15
|
export function transform(node: FieldNode, transformState: TransformState): LuvioFieldNode {
|
|
16
16
|
const { name, alias, arguments: fieldArgs, selectionSet, directives } = node;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FragmentSpreadNode } from 'graphql/language';
|
|
2
|
-
import { LuvioFragmentSpreadNode } from './ast';
|
|
1
|
+
import type { FragmentSpreadNode } from 'graphql/language';
|
|
2
|
+
import type { LuvioFragmentSpreadNode } from './ast';
|
|
3
3
|
import { transform as transformDirectiveNode } from './directive-node';
|
|
4
|
-
import { TransformState } from './operation/query';
|
|
4
|
+
import type { TransformState } from './operation/query';
|
|
5
5
|
|
|
6
6
|
export function transform(
|
|
7
7
|
node: FragmentSpreadNode,
|
package/src/fragment.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FragmentDefinitionNode } from 'graphql/language';
|
|
2
|
-
import { LuvioFieldNode, LuvioFragmentDefinitionNode, LuvioSelectionNode } from './ast';
|
|
1
|
+
import type { FragmentDefinitionNode } from 'graphql/language';
|
|
2
|
+
import type { LuvioFieldNode, LuvioFragmentDefinitionNode, LuvioSelectionNode } from './ast';
|
|
3
3
|
import { selectionSetVisitor } from './visitor';
|
|
4
4
|
import { transform as transformDirectiveNode } from './directive-node';
|
|
5
5
|
import { NODE_KIND_OBJECT_FIELD_SELECTION } from './constants';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { InlineFragmentNode } from 'graphql/language';
|
|
2
|
-
import { LuvioInlineFragmentNode } from './ast';
|
|
1
|
+
import type { InlineFragmentNode } from 'graphql/language';
|
|
2
|
+
import type { LuvioInlineFragmentNode } from './ast';
|
|
3
3
|
import { transform as transformDirectiveNode } from './directive-node';
|
|
4
|
-
import { TransformState } from './operation/query';
|
|
4
|
+
import type { TransformState } from './operation/query';
|
|
5
5
|
|
|
6
6
|
export function transform(
|
|
7
7
|
node: InlineFragmentNode,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GraphQLSchema } from 'graphql';
|
|
2
|
+
|
|
3
|
+
interface LuvioGraphQLSchemaParams {
|
|
4
|
+
schema: GraphQLSchema;
|
|
5
|
+
schemaName: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class LuvioGraphQLSchema {
|
|
9
|
+
// INVARIANT - Do not mutate the source schema, or add special AST or schema syntax,
|
|
10
|
+
// just store additional information alongside it. In this way - we can accept this extra data in basically any format (RAML, JSON, YML)
|
|
11
|
+
schema: Readonly<GraphQLSchema>;
|
|
12
|
+
schemaName: Readonly<string>;
|
|
13
|
+
|
|
14
|
+
constructor(luvioSchemaParams: Readonly<LuvioGraphQLSchemaParams>) {
|
|
15
|
+
this.schemaName = luvioSchemaParams.schemaName;
|
|
16
|
+
this.schema = luvioSchemaParams.schema;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/main.ts
CHANGED
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
IntValueNode,
|
|
6
6
|
StringValueNode,
|
|
7
7
|
} from 'graphql/language';
|
|
8
|
+
|
|
9
|
+
import { buildASTSchema } from 'graphql/utilities';
|
|
8
10
|
import {
|
|
9
11
|
LuvioDocumentNode,
|
|
10
12
|
LuvioArgumentNode,
|
|
@@ -25,14 +27,29 @@ import {
|
|
|
25
27
|
LuvioTypeNode,
|
|
26
28
|
} from './ast';
|
|
27
29
|
import { transform } from './document';
|
|
30
|
+
import { LuvioGraphQLSchema } from './luvio-schema';
|
|
28
31
|
|
|
32
|
+
/*
|
|
33
|
+
Deprecated - Remove after existing usages are removed.
|
|
34
|
+
*/
|
|
29
35
|
export function parseAndVisit(source: string): LuvioDocumentNode {
|
|
30
|
-
// TODO: handle generic <Type>
|
|
31
36
|
const ast = parse(source);
|
|
32
37
|
return transform(ast);
|
|
33
38
|
}
|
|
34
39
|
|
|
35
|
-
|
|
40
|
+
export function parseLuvioSchema(source: string, schemaName: string): LuvioGraphQLSchema {
|
|
41
|
+
const schema = buildASTSchema(parse(source));
|
|
42
|
+
return new LuvioGraphQLSchema({
|
|
43
|
+
schema,
|
|
44
|
+
schemaName,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { LuvioGraphQLSchema };
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated - Schema-backed adapters will use standard graphql types re-exported from @luvio/graphql
|
|
52
|
+
*/
|
|
36
53
|
export {
|
|
37
54
|
BooleanValueNode,
|
|
38
55
|
FloatValueNode,
|
package/src/operation/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OperationDefinitionNode } from 'graphql/language';
|
|
2
|
-
import { LuvioOperationDefinitionNode } from '../ast';
|
|
1
|
+
import type { OperationDefinitionNode } from 'graphql/language';
|
|
2
|
+
import type { LuvioOperationDefinitionNode } from '../ast';
|
|
3
3
|
import { transform as QueryTransform } from './query';
|
|
4
4
|
|
|
5
5
|
export function transform(node: OperationDefinitionNode): LuvioOperationDefinitionNode {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OperationDefinitionNode, VariableDefinitionNode } from 'graphql/language';
|
|
2
|
-
import { LuvioFieldNode, LuvioOperationDefinitionNode, LuvioSelectionNode } from '../../ast';
|
|
1
|
+
import type { OperationDefinitionNode, VariableDefinitionNode } from 'graphql/language';
|
|
2
|
+
import type { LuvioFieldNode, LuvioOperationDefinitionNode, LuvioSelectionNode } from '../../ast';
|
|
3
3
|
import { selectionSetVisitor } from '../../visitor';
|
|
4
4
|
import { transform as transformVariableDefinition } from '../../variable-definition';
|
|
5
5
|
import { transform as transformDirectiveNode } from '../../directive-node';
|
package/src/type-node.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { TypeNode } from 'graphql/language';
|
|
2
|
-
import {
|
|
1
|
+
import type { TypeNode } from 'graphql/language';
|
|
2
|
+
import type { LuvioTypeNode } from './ast';
|
|
3
|
+
import { isListTypeNode, isNamedTypeNode, isNonNullTypeNode } from './ast';
|
|
3
4
|
import { NODE_KIND_NAMED_TYPE, NODE_KIND_LIST_TYPE, NODE_KIND_NON_NULL_TYPE } from './constants';
|
|
4
5
|
|
|
5
6
|
export function transform(node: TypeNode): LuvioTypeNode {
|
package/src/value-node.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ValueNode } from 'graphql/language';
|
|
2
|
-
import { LuvioValueNode } from './ast';
|
|
3
|
-
import { TransformState } from './operation/query';
|
|
1
|
+
import type { ValueNode } from 'graphql/language';
|
|
2
|
+
import type { LuvioValueNode } from './ast';
|
|
3
|
+
import type { TransformState } from './operation/query';
|
|
4
4
|
|
|
5
5
|
export function transform(node: ValueNode, transformState: TransformState): LuvioValueNode {
|
|
6
6
|
switch (node.kind) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { VariableDefinitionNode } from 'graphql/language';
|
|
2
|
-
import { LuvioVariableDefinitionNode } from './ast';
|
|
3
|
-
import { TransformState } from './operation/query';
|
|
1
|
+
import type { VariableDefinitionNode } from 'graphql/language';
|
|
2
|
+
import type { LuvioVariableDefinitionNode } from './ast';
|
|
3
|
+
import type { TransformState } from './operation/query';
|
|
4
4
|
import { transform as transformTypeNode } from './type-node';
|
|
5
5
|
import { transform as transformValueNode } from './value-node';
|
|
6
6
|
|
package/src/visitor.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ASTNode, ASTVisitor
|
|
2
|
-
import {
|
|
1
|
+
import type { ASTNode, ASTVisitor } from 'graphql/language';
|
|
2
|
+
import { visit } from 'graphql/language';
|
|
3
|
+
import type { LuvioSelectionNode } from './ast';
|
|
3
4
|
import {
|
|
4
5
|
NODE_KIND_CUSTOM_FIELD_SELECTION,
|
|
5
6
|
NODE_KIND_FIELD,
|
|
@@ -10,7 +11,7 @@ import {
|
|
|
10
11
|
import { transform as transformFieldNode } from './field-node';
|
|
11
12
|
import { transform as transformFragmentSpreadNode } from './fragment-spread-node';
|
|
12
13
|
import { transform as transformInlineFragmentNode } from './inline-fragment-node';
|
|
13
|
-
import { TransformState } from './operation/query';
|
|
14
|
+
import type { TransformState } from './operation/query';
|
|
14
15
|
|
|
15
16
|
export function selectionSetVisitor(
|
|
16
17
|
ast: ASTNode,
|