@luvio/graphql-parser 0.73.0 → 0.73.5

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.
@@ -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
+ });
@@ -0,0 +1,18 @@
1
+ import { 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,27 @@ 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
- // type exports
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
+ /*
49
+ Deprecated - Schema-backed adapters will use standard graphql types re-exported from @luvio/graphql
50
+ */
36
51
  export {
37
52
  BooleanValueNode,
38
53
  FloatValueNode,