graphql-buddy 0.0.0 → 0.1.0

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 (59) hide show
  1. package/README.md +23 -0
  2. package/dist/api.d.ts +42 -8
  3. package/dist/api.js +9 -5
  4. package/dist/chunk-ZIUWDMA7.js +190 -0
  5. package/dist/chunk-ZIUWDMA7.js.map +1 -0
  6. package/dist/cli.js +21 -6
  7. package/dist/cli.js.map +1 -1
  8. package/package.json +1 -1
  9. package/pnpm-workspace.yaml +3 -0
  10. package/src/api/commands/bundle.test.ts +4 -4
  11. package/src/api/commands/bundle.ts +1 -1
  12. package/src/api/commands/validate.test.ts +125 -24
  13. package/src/api/commands/validate.ts +36 -12
  14. package/src/api/shared/GraphqlFiles.ts +61 -0
  15. package/src/api/shared/index.ts +3 -0
  16. package/src/api/shared/loadDocuments.ts +48 -0
  17. package/src/api/shared/loadSchema.ts +11 -57
  18. package/src/api/shared/validateDocuments.ts +45 -0
  19. package/src/cli/commands/validate.ts +22 -5
  20. package/src/cli/index.ts +2 -0
  21. package/test_fixtures/documents/aliased_import/documents/AllFoo.graphql +7 -0
  22. package/test_fixtures/documents/aliased_import/documents/fragments/FooFields.graphql +4 -0
  23. package/test_fixtures/documents/aliased_import/schema/schema.graphql +20 -0
  24. package/test_fixtures/documents/anonymous_operation/documents/Anonymous.graphql +11 -0
  25. package/test_fixtures/documents/anonymous_operation/schema/schema.graphql +20 -0
  26. package/test_fixtures/documents/broken_import/documents/AllFoo.graphql +7 -0
  27. package/test_fixtures/documents/broken_import/schema/schema.graphql +20 -0
  28. package/test_fixtures/documents/duplicate_names/documents/First.graphql +5 -0
  29. package/test_fixtures/documents/duplicate_names/documents/Second.graphql +5 -0
  30. package/test_fixtures/documents/duplicate_names/schema/schema.graphql +20 -0
  31. package/test_fixtures/documents/fragment_library/documents/FooFields.graphql +4 -0
  32. package/test_fixtures/documents/fragment_library/schema/schema.graphql +20 -0
  33. package/test_fixtures/documents/imported_fragment/documents/AllFoo.graphql +12 -0
  34. package/test_fixtures/documents/imported_fragment/documents/FooFields.graphql +4 -0
  35. package/test_fixtures/documents/imported_fragment/schema/schema.graphql +20 -0
  36. package/test_fixtures/documents/invalid_fragment/documents/FooFields.graphql +4 -0
  37. package/test_fixtures/documents/invalid_fragment/schema/schema.graphql +20 -0
  38. package/test_fixtures/documents/missing_argument/documents/MissingArgument.graphql +5 -0
  39. package/test_fixtures/documents/missing_argument/schema/schema.graphql +20 -0
  40. package/test_fixtures/documents/mixed_sdl/documents/MixedSdl.graphql +9 -0
  41. package/test_fixtures/documents/mixed_sdl/schema/schema.graphql +20 -0
  42. package/test_fixtures/documents/nested_imports/documents/AllFoo.graphql +7 -0
  43. package/test_fixtures/documents/nested_imports/documents/BarFields.graphql +5 -0
  44. package/test_fixtures/documents/nested_imports/documents/FooFields.graphql +8 -0
  45. package/test_fixtures/documents/nested_imports/schema/schema.graphql +20 -0
  46. package/test_fixtures/documents/unknown_field/documents/BadFoo.graphql +6 -0
  47. package/test_fixtures/documents/unknown_field/schema/schema.graphql +20 -0
  48. package/test_fixtures/documents/unused_variable/documents/UnusedVariable.graphql +5 -0
  49. package/test_fixtures/documents/unused_variable/schema/schema.graphql +20 -0
  50. package/dist/chunk-Z7B4AQ2U.js +0 -124
  51. package/dist/chunk-Z7B4AQ2U.js.map +0 -1
  52. /package/test_fixtures/{missing_scalar → schema/missing_scalar}/schema.graphql +0 -0
  53. /package/test_fixtures/{multiple_files → schema/multiple_files}/Bar.graphql +0 -0
  54. /package/test_fixtures/{multiple_files → schema/multiple_files}/Baz.graphql +0 -0
  55. /package/test_fixtures/{multiple_files → schema/multiple_files}/Foo.graphql +0 -0
  56. /package/test_fixtures/{multiple_files → schema/multiple_files}/Mutation.graphql +0 -0
  57. /package/test_fixtures/{multiple_files → schema/multiple_files}/Query.graphql +0 -0
  58. /package/test_fixtures/{single_file → schema/single_file}/schema.graphql +0 -0
  59. /package/test_fixtures/{single_file_with_extra_deps → schema/single_file_with_extra_deps}/schema.graphql +0 -0
@@ -0,0 +1,4 @@
1
+ fragment FooFields on Foo {
2
+ id
3
+ name
4
+ }
@@ -0,0 +1,20 @@
1
+ type Query {
2
+ allFoo: [Foo!]!
3
+ foo(id: ID!): Foo
4
+ }
5
+
6
+ type Foo {
7
+ id: ID!
8
+ name: String
9
+ bar: Bar
10
+ }
11
+
12
+ type Bar {
13
+ baz: Baz
14
+ }
15
+
16
+ type Baz {
17
+ dateCreated: DateTime!
18
+ }
19
+
20
+ scalar DateTime
@@ -0,0 +1,12 @@
1
+ #import "./FooFields.graphql"
2
+
3
+ query AllFoo {
4
+ allFoo {
5
+ ...FooFields
6
+ bar {
7
+ baz {
8
+ dateCreated
9
+ }
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,4 @@
1
+ fragment FooFields on Foo {
2
+ id
3
+ name
4
+ }
@@ -0,0 +1,20 @@
1
+ type Query {
2
+ allFoo: [Foo!]!
3
+ foo(id: ID!): Foo
4
+ }
5
+
6
+ type Foo {
7
+ id: ID!
8
+ name: String
9
+ bar: Bar
10
+ }
11
+
12
+ type Bar {
13
+ baz: Baz
14
+ }
15
+
16
+ type Baz {
17
+ dateCreated: DateTime!
18
+ }
19
+
20
+ scalar DateTime
@@ -0,0 +1,4 @@
1
+ fragment FooFields on Foo {
2
+ id
3
+ thisFieldDoesNotExist
4
+ }
@@ -0,0 +1,20 @@
1
+ type Query {
2
+ allFoo: [Foo!]!
3
+ foo(id: ID!): Foo
4
+ }
5
+
6
+ type Foo {
7
+ id: ID!
8
+ name: String
9
+ bar: Bar
10
+ }
11
+
12
+ type Bar {
13
+ baz: Baz
14
+ }
15
+
16
+ type Baz {
17
+ dateCreated: DateTime!
18
+ }
19
+
20
+ scalar DateTime
@@ -0,0 +1,5 @@
1
+ query MissingArgument {
2
+ foo {
3
+ id
4
+ }
5
+ }
@@ -0,0 +1,20 @@
1
+ type Query {
2
+ allFoo: [Foo!]!
3
+ foo(id: ID!): Foo
4
+ }
5
+
6
+ type Foo {
7
+ id: ID!
8
+ name: String
9
+ bar: Bar
10
+ }
11
+
12
+ type Bar {
13
+ baz: Baz
14
+ }
15
+
16
+ type Baz {
17
+ dateCreated: DateTime!
18
+ }
19
+
20
+ scalar DateTime
@@ -0,0 +1,9 @@
1
+ query MixedSdl {
2
+ allFoo {
3
+ id
4
+ }
5
+ }
6
+
7
+ type Bogus {
8
+ x: Int
9
+ }
@@ -0,0 +1,20 @@
1
+ type Query {
2
+ allFoo: [Foo!]!
3
+ foo(id: ID!): Foo
4
+ }
5
+
6
+ type Foo {
7
+ id: ID!
8
+ name: String
9
+ bar: Bar
10
+ }
11
+
12
+ type Bar {
13
+ baz: Baz
14
+ }
15
+
16
+ type Baz {
17
+ dateCreated: DateTime!
18
+ }
19
+
20
+ scalar DateTime
@@ -0,0 +1,7 @@
1
+ #import "./FooFields.graphql"
2
+
3
+ query AllFoo {
4
+ allFoo {
5
+ ...FooFields
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ fragment BarFields on Bar {
2
+ baz {
3
+ dateCreated
4
+ }
5
+ }
@@ -0,0 +1,8 @@
1
+ #import "./BarFields.graphql"
2
+
3
+ fragment FooFields on Foo {
4
+ id
5
+ bar {
6
+ ...BarFields
7
+ }
8
+ }
@@ -0,0 +1,20 @@
1
+ type Query {
2
+ allFoo: [Foo!]!
3
+ foo(id: ID!): Foo
4
+ }
5
+
6
+ type Foo {
7
+ id: ID!
8
+ name: String
9
+ bar: Bar
10
+ }
11
+
12
+ type Bar {
13
+ baz: Baz
14
+ }
15
+
16
+ type Baz {
17
+ dateCreated: DateTime!
18
+ }
19
+
20
+ scalar DateTime
@@ -0,0 +1,6 @@
1
+ query BadFoo {
2
+ allFoo {
3
+ id
4
+ thisFieldDoesNotExist
5
+ }
6
+ }
@@ -0,0 +1,20 @@
1
+ type Query {
2
+ allFoo: [Foo!]!
3
+ foo(id: ID!): Foo
4
+ }
5
+
6
+ type Foo {
7
+ id: ID!
8
+ name: String
9
+ bar: Bar
10
+ }
11
+
12
+ type Bar {
13
+ baz: Baz
14
+ }
15
+
16
+ type Baz {
17
+ dateCreated: DateTime!
18
+ }
19
+
20
+ scalar DateTime
@@ -0,0 +1,5 @@
1
+ query UnusedVariable($id: ID!) {
2
+ allFoo {
3
+ id
4
+ }
5
+ }
@@ -0,0 +1,20 @@
1
+ type Query {
2
+ allFoo: [Foo!]!
3
+ foo(id: ID!): Foo
4
+ }
5
+
6
+ type Foo {
7
+ id: ID!
8
+ name: String
9
+ bar: Bar
10
+ }
11
+
12
+ type Bar {
13
+ baz: Baz
14
+ }
15
+
16
+ type Baz {
17
+ dateCreated: DateTime!
18
+ }
19
+
20
+ scalar DateTime
@@ -1,124 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __async = (__this, __arguments, generator) => {
21
- return new Promise((resolve2, reject) => {
22
- var fulfilled = (value) => {
23
- try {
24
- step(generator.next(value));
25
- } catch (e) {
26
- reject(e);
27
- }
28
- };
29
- var rejected = (value) => {
30
- try {
31
- step(generator.throw(value));
32
- } catch (e) {
33
- reject(e);
34
- }
35
- };
36
- var step = (x) => x.done ? resolve2(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
- step((generator = generator.apply(__this, __arguments)).next());
38
- });
39
- };
40
-
41
- // src/api/commands/bundle.ts
42
- import * as graphqlToolsUtils from "@graphql-tools/utils";
43
- import * as graphql from "graphql";
44
-
45
- // src/api/shared/loadSchema.ts
46
- import * as nodeFs from "fs/promises";
47
- import * as nodePath from "path";
48
- import * as graphqlFileLoader from "@graphql-tools/graphql-file-loader";
49
- import * as graphqlLoad from "@graphql-tools/load";
50
- import * as glob from "glob";
51
- var loadSchema2 = (options) => __async(null, null, function* () {
52
- const { files, pathAliases } = options.normalized ? options : yield normalizeLoadSchemaOptions(options);
53
- for (const file of files) {
54
- try {
55
- yield nodeFs.access(file, nodeFs.constants.F_OK);
56
- } catch (e) {
57
- throw new Error(`File does not exist: ${file}`);
58
- }
59
- }
60
- return graphqlLoad.loadSchema(files, {
61
- loaders: [new graphqlFileLoader.GraphQLFileLoader()],
62
- pathAliases: {
63
- mappings: Object.fromEntries(pathAliases.entries())
64
- }
65
- });
66
- });
67
- var normalizeLoadSchemaOptions = (options) => __async(null, null, function* () {
68
- var _a;
69
- const base = (_a = options.base) != null ? _a : process.cwd();
70
- const files = yield glob.glob(
71
- options.files.map((file) => nodePath.resolve(base, file))
72
- );
73
- const pathAliases = /* @__PURE__ */ new Map();
74
- if (options.pathAliases != null) {
75
- for (const [alias, source] of options.pathAliases.entries()) {
76
- pathAliases.set(alias, nodePath.resolve(base, source));
77
- }
78
- }
79
- return {
80
- normalized: true,
81
- files,
82
- pathAliases
83
- };
84
- });
85
-
86
- // src/api/commands/bundle.ts
87
- var bundle = (options) => __async(null, null, function* () {
88
- var _a;
89
- const shake = (_a = options.shake) != null ? _a : true;
90
- let schema = yield loadSchema2(options.schema);
91
- if (shake) {
92
- schema = graphqlToolsUtils.pruneSchema(schema);
93
- }
94
- return graphql.printSchema(schema);
95
- });
96
-
97
- // src/api/commands/validate.ts
98
- import * as stringifyObject from "stringify-object";
99
- var validate = (options) => __async(null, null, function* () {
100
- const normalizedSchemaOptions = yield normalizeLoadSchemaOptions(
101
- options.schema
102
- );
103
- yield loadSchema2(normalizedSchemaOptions);
104
- return createValidationStamp(__spreadProps(__spreadValues({}, options), {
105
- schema: normalizedSchemaOptions
106
- }));
107
- });
108
- var createValidationStamp = (options) => stringifyObject.default(
109
- { options, outcome: { valid: true } },
110
- {
111
- indent: ` `,
112
- filter: (container, property) => !(container === options.schema && property === `normalized`)
113
- }
114
- );
115
-
116
- export {
117
- __spreadValues,
118
- __async,
119
- loadSchema2 as loadSchema,
120
- normalizeLoadSchemaOptions,
121
- bundle,
122
- validate
123
- };
124
- //# sourceMappingURL=chunk-Z7B4AQ2U.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/api/commands/bundle.ts","../src/api/shared/loadSchema.ts","../src/api/commands/validate.ts"],"sourcesContent":["import * as graphqlToolsUtils from '@graphql-tools/utils';\nimport * as graphql from 'graphql';\n\nimport * as shared from '../shared';\n\nexport type BundleOptions = {\n schema: shared.LoadSchemaOptions;\n\n // Defaults to true.\n shake?: boolean | null;\n};\n\n/**\n * Bundles multiple schema together into a single file.\n *\n * @param options - Bundle options.\n *\n * @returns The merged schema as text.\n */\nexport const bundle = async (options: BundleOptions): Promise<string> => {\n const shake = options.shake ?? true;\n\n let schema = await shared.loadSchema(options.schema);\n if (shake) {\n schema = graphqlToolsUtils.pruneSchema(schema);\n }\n\n return graphql.printSchema(schema);\n};\n","import * as nodeFs from 'node:fs/promises';\nimport * as nodePath from 'node:path';\n\nimport * as graphqlFileLoader from '@graphql-tools/graphql-file-loader';\nimport * as graphqlLoad from '@graphql-tools/load';\nimport * as glob from 'glob';\n\nimport type * as graphql from 'graphql';\n\nexport type LoadSchemaOptions = {\n normalized?: false | null;\n\n // Relative paths will be resolved using `base`.\n //\n // Also accepts glob patterns.\n files: Array<string>;\n\n // Directory from which `files` are resolved.\n //\n // Defaults to `process.cwd()`.\n base?: string | null;\n\n // See @graphql-tools/import#PathAliases\n //\n // Note that relative paths will be resolved relative to `base` to maintain\n // parity with `files`.\n pathAliases?: Map<string, string> | null;\n};\n\nexport const loadSchema = async (\n options: LoadSchemaOptions | NormalizedLoadSchemaOptions,\n): Promise<graphql.GraphQLSchema> => {\n const { files, pathAliases } = options.normalized\n ? options\n : await normalizeLoadSchemaOptions(options);\n\n // @graphql-tools/graphql-file-loader silently skips input files which are not\n // found. I suspect this is so that it can delegate missing inputs to other\n // loaders. For our purposes, this is undesirable because we want to inform\n // clients if expected inputs are missing. For that reason, we manually\n // validate that the files exist first.\n for (const file of files) {\n try {\n await nodeFs.access(file, nodeFs.constants.F_OK);\n } catch {\n throw new Error(`File does not exist: ${file}`);\n }\n }\n\n return graphqlLoad.loadSchema(files, {\n loaders: [new graphqlFileLoader.GraphQLFileLoader()],\n pathAliases: {\n mappings: Object.fromEntries(pathAliases.entries()),\n },\n });\n};\n\nexport type NormalizedLoadSchemaOptions = {\n normalized: true;\n\n // Absolute paths.\n files: Array<string>;\n\n // See @graphql-tools/import#PathAliases\n pathAliases: Map<string, string>;\n};\n\nexport const normalizeLoadSchemaOptions = async (\n options: LoadSchemaOptions,\n): Promise<NormalizedLoadSchemaOptions> => {\n const base = options.base ?? process.cwd();\n const files = await glob.glob(\n options.files.map((file) => nodePath.resolve(base, file)),\n );\n\n const pathAliases = new Map<string, string>();\n if (options.pathAliases != null) {\n for (const [alias, source] of options.pathAliases.entries()) {\n pathAliases.set(alias, nodePath.resolve(base, source));\n }\n }\n\n return {\n normalized: true,\n files,\n pathAliases,\n };\n};\n","import * as stringifyObject from 'stringify-object';\n\nimport * as shared from '../shared';\n\nexport type ValidateOptions = {\n schema: shared.LoadSchemaOptions;\n};\n\n/**\n * Validates that the provided GraphQL schema contain valid syntax and have no\n * unknown symbols.\n *\n * @param options - Validate options.\n *\n * @returns If validation is successful, returns a validation stamp: a text blob\n * describing the successful outcome and options used during validation. This\n * is often useful in build systems where a build step *must* emit a file. If\n * validation fails, a runtime error will be thrown.\n */\nexport const validate = async (options: ValidateOptions): Promise<string> => {\n // We manually normalize the `LoadSchemaOptions` so that we can write the most\n // accurate data in our validation stamp. For example, normalization expands\n // globs and resolves absolute paths. These are critical steps to ensure the\n // validation stamp describes without ambiguity which schema were loaded.\n const normalizedSchemaOptions = await shared.normalizeLoadSchemaOptions(\n options.schema,\n );\n\n await shared.loadSchema(normalizedSchemaOptions);\n\n return createValidationStamp({\n ...options,\n schema: normalizedSchemaOptions,\n });\n};\n\nconst createValidationStamp = (\n options: Omit<ValidateOptions, `schema`> & {\n schema: shared.NormalizedLoadSchemaOptions;\n },\n): string =>\n stringifyObject.default(\n { options, outcome: { valid: true } },\n {\n indent: ` `,\n filter: (container, property) =>\n !(container === options.schema && property === `normalized`),\n },\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,YAAY,uBAAuB;AACnC,YAAY,aAAa;;;ACDzB,YAAY,YAAY;AACxB,YAAY,cAAc;AAE1B,YAAY,uBAAuB;AACnC,YAAY,iBAAiB;AAC7B,YAAY,UAAU;AAwBf,IAAMA,cAAa,CACxB,YACmC;AACnC,QAAM,EAAE,OAAO,YAAY,IAAI,QAAQ,aACnC,UACA,MAAM,2BAA2B,OAAO;AAO5C,aAAW,QAAQ,OAAO;AACxB,QAAI;AACF,YAAa,cAAO,MAAa,iBAAU,IAAI;AAAA,IACjD,SAAQ;AACN,YAAM,IAAI,MAAM,wBAAwB,IAAI,EAAE;AAAA,IAChD;AAAA,EACF;AAEA,SAAmB,uBAAW,OAAO;AAAA,IACnC,SAAS,CAAC,IAAsB,oCAAkB,CAAC;AAAA,IACnD,aAAa;AAAA,MACX,UAAU,OAAO,YAAY,YAAY,QAAQ,CAAC;AAAA,IACpD;AAAA,EACF,CAAC;AACH;AAYO,IAAM,6BAA6B,CACxC,YACyC;AArE3C;AAsEE,QAAM,QAAO,aAAQ,SAAR,YAAgB,QAAQ,IAAI;AACzC,QAAM,QAAQ,MAAW;AAAA,IACvB,QAAQ,MAAM,IAAI,CAAC,SAAkB,iBAAQ,MAAM,IAAI,CAAC;AAAA,EAC1D;AAEA,QAAM,cAAc,oBAAI,IAAoB;AAC5C,MAAI,QAAQ,eAAe,MAAM;AAC/B,eAAW,CAAC,OAAO,MAAM,KAAK,QAAQ,YAAY,QAAQ,GAAG;AAC3D,kBAAY,IAAI,OAAgB,iBAAQ,MAAM,MAAM,CAAC;AAAA,IACvD;AAAA,EACF;AAEA,SAAO;AAAA,IACL,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,EACF;AACF;;;ADpEO,IAAM,SAAS,CAAO,YAA4C;AAnBzE;AAoBE,QAAM,SAAQ,aAAQ,UAAR,YAAiB;AAE/B,MAAI,SAAS,MAAaC,YAAW,QAAQ,MAAM;AACnD,MAAI,OAAO;AACT,aAA2B,8BAAY,MAAM;AAAA,EAC/C;AAEA,SAAe,oBAAY,MAAM;AACnC;;;AE5BA,YAAY,qBAAqB;AAmB1B,IAAM,WAAW,CAAO,YAA8C;AAK3E,QAAM,0BAA0B,MAAa;AAAA,IAC3C,QAAQ;AAAA,EACV;AAEA,QAAaC,YAAW,uBAAuB;AAE/C,SAAO,sBAAsB,iCACxB,UADwB;AAAA,IAE3B,QAAQ;AAAA,EACV,EAAC;AACH;AAEA,IAAM,wBAAwB,CAC5B,YAIgB;AAAA,EACd,EAAE,SAAS,SAAS,EAAE,OAAO,KAAK,EAAE;AAAA,EACpC;AAAA,IACE,QAAQ;AAAA,IACR,QAAQ,CAAC,WAAW,aAClB,EAAE,cAAc,QAAQ,UAAU,aAAa;AAAA,EACnD;AACF;","names":["loadSchema","loadSchema","loadSchema"]}