@cedarjs/realtime 2.7.1-next.0 → 2.7.1-next.34

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.
@@ -1,4 +1,4 @@
1
- import type { Plugin } from '@envelop/core';
1
+ import type { Plugin as EnvelopPlugin } from '@envelop/core';
2
2
  import type { CreateRedisEventTargetArgs } from '@graphql-yoga/redis-event-target';
3
3
  import type { PubSub } from '@graphql-yoga/subscription';
4
4
  import { createPubSub } from '@graphql-yoga/subscription';
@@ -95,9 +95,9 @@ export declare class RedisLiveQueryStore {
95
95
  }
96
96
  export declare let liveQueryStore: LiveQueryStorageMechanism | undefined;
97
97
  export declare let pubSub: ReturnType<typeof createPubSub> | undefined;
98
- export declare const useCedarRealtime: (options: CedarRealtimeOptions) => Plugin;
98
+ export declare const useCedarRealtime: (options: CedarRealtimeOptions) => EnvelopPlugin;
99
99
  /**
100
100
  * @deprecated Use `useCedarRealtime` instead.
101
101
  */
102
- export declare const useRedwoodRealtime: (options: CedarRealtimeOptions) => Plugin;
102
+ export declare const useRedwoodRealtime: (options: CedarRealtimeOptions) => EnvelopPlugin;
103
103
  //# sourceMappingURL=useCedarRealtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCedarRealtime.d.ts","sourceRoot":"","sources":["../../../src/graphql/plugins/useCedarRealtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAO3C,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAA;AAClF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AAC3E,OAAO,KAAK,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,SAAS,CAAA;AAGxD,OAAO,EAAE,QAAQ,EAAE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AA;AAC5E,eAAO,IAAI,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,GAAG,SAAqB,CAAA;AAE1E,eAAO,MAAM,gBAAgB,GAC3B,SAAS,oBAAoB,KAC5B,aAkGF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAC7B,SAAS,oBAAoB,KAC5B,aAEF,CAAA"}
@@ -0,0 +1,142 @@
1
+ import { useLiveQuery } from "@envelop/live-query";
2
+ import { mergeSchemas } from "@graphql-tools/schema";
3
+ import { astFromDirective } from "@graphql-tools/utils";
4
+ import { useDeferStream } from "@graphql-yoga/plugin-defer-stream";
5
+ import { useGraphQLSSE } from "@graphql-yoga/plugin-graphql-sse";
6
+ import { createRedisEventTarget } from "@graphql-yoga/redis-event-target";
7
+ import { createPubSub } from "@graphql-yoga/subscription";
8
+ import { GraphQLLiveDirective } from "@n1ru4l/graphql-live-query";
9
+ import { InMemoryLiveQueryStore } from "@n1ru4l/in-memory-live-query-store";
10
+ import { print } from "graphql";
11
+ import { Repeater } from "graphql-yoga";
12
+ const liveDirectiveTypeDefs = print(
13
+ astFromDirective(GraphQLLiveDirective)
14
+ );
15
+ class RedisLiveQueryStore {
16
+ pub;
17
+ sub;
18
+ channel;
19
+ liveQueryStore;
20
+ constructor(pub, sub, channel, liveQueryStore2) {
21
+ this.pub = pub;
22
+ this.sub = sub;
23
+ this.liveQueryStore = liveQueryStore2;
24
+ this.channel = channel;
25
+ this.sub.subscribe(this.channel, (err) => {
26
+ if (err) {
27
+ throw err;
28
+ }
29
+ });
30
+ this.sub.on("message", (channel2, resourceIdentifier) => {
31
+ if (channel2 === this.channel && resourceIdentifier) {
32
+ this.liveQueryStore.invalidate(resourceIdentifier);
33
+ }
34
+ });
35
+ }
36
+ async invalidate(identifiers) {
37
+ if (typeof identifiers === "string") {
38
+ identifiers = [identifiers];
39
+ }
40
+ for (const identifier of identifiers) {
41
+ this.pub.publish(this.channel, identifier);
42
+ }
43
+ }
44
+ makeExecute(execute) {
45
+ return this.liveQueryStore.makeExecute(execute);
46
+ }
47
+ }
48
+ let liveQueryStore = void 0;
49
+ let pubSub = void 0;
50
+ const useCedarRealtime = (options) => {
51
+ let liveQueriesEnabled = false;
52
+ let subscriptionsEnabled = false;
53
+ let liveQueryPlugin;
54
+ const inMemoryLiveQueryStore = new InMemoryLiveQueryStore();
55
+ liveQueryStore = {};
56
+ pubSub = {};
57
+ const wasLiveQueryAdded = Symbol.for("useCedarRealtime.wasLiveQueryAdded");
58
+ if (options.liveQueries?.store) {
59
+ if (options.liveQueries.store === "in-memory") {
60
+ liveQueriesEnabled = true;
61
+ liveQueryStore = inMemoryLiveQueryStore;
62
+ liveQueryPlugin = useLiveQuery({ liveQueryStore });
63
+ } else if (options.liveQueries.store.redis) {
64
+ liveQueriesEnabled = true;
65
+ liveQueryStore = new RedisLiveQueryStore(
66
+ options.liveQueries.store.redis.publishClient,
67
+ options.liveQueries.store.redis.subscribeClient,
68
+ options.liveQueries.store.redis.channel || "live-query-invalidations",
69
+ inMemoryLiveQueryStore
70
+ );
71
+ liveQueryPlugin = useLiveQuery({ liveQueryStore });
72
+ } else {
73
+ throw new Error("Invalid live query store configuration.");
74
+ }
75
+ }
76
+ if (options.subscriptions?.store) {
77
+ if (options.subscriptions.store === "in-memory") {
78
+ subscriptionsEnabled = true;
79
+ pubSub = createPubSub();
80
+ } else if (options.subscriptions.store.redis) {
81
+ subscriptionsEnabled = true;
82
+ const eventTarget = createRedisEventTarget({
83
+ publishClient: options.subscriptions.store.redis.publishClient,
84
+ subscribeClient: options.subscriptions.store.redis.subscribeClient
85
+ });
86
+ pubSub = createPubSub({ eventTarget });
87
+ } else {
88
+ throw new Error("Invalid subscriptions store configuration.");
89
+ }
90
+ }
91
+ return {
92
+ onSchemaChange({ replaceSchema, schema }) {
93
+ if (schema.extensions?.[wasLiveQueryAdded] === true) {
94
+ return;
95
+ }
96
+ if (liveQueriesEnabled) {
97
+ const liveSchema = mergeSchemas({
98
+ schemas: [schema],
99
+ typeDefs: [liveDirectiveTypeDefs]
100
+ });
101
+ liveSchema.extensions = {
102
+ ...schema.extensions,
103
+ [wasLiveQueryAdded]: true
104
+ };
105
+ replaceSchema(liveSchema);
106
+ }
107
+ },
108
+ onPluginInit({ addPlugin }) {
109
+ if (liveQueriesEnabled && liveQueryPlugin) {
110
+ addPlugin(liveQueryPlugin);
111
+ }
112
+ if (subscriptionsEnabled) {
113
+ addPlugin(useGraphQLSSE());
114
+ }
115
+ if (options.enableDeferStream) {
116
+ addPlugin(useDeferStream());
117
+ }
118
+ },
119
+ onContextBuilding() {
120
+ return ({ extendContext }) => {
121
+ extendContext({
122
+ liveQueryStore: liveQueriesEnabled && liveQueryStore,
123
+ pubSub: subscriptionsEnabled && pubSub
124
+ });
125
+ };
126
+ }
127
+ };
128
+ };
129
+ const useRedwoodRealtime = (options) => {
130
+ return useCedarRealtime(options);
131
+ };
132
+ export {
133
+ InMemoryLiveQueryStore,
134
+ RedisLiveQueryStore,
135
+ Repeater,
136
+ createPubSub,
137
+ liveDirectiveTypeDefs,
138
+ liveQueryStore,
139
+ pubSub,
140
+ useCedarRealtime,
141
+ useRedwoodRealtime
142
+ };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { useCedarRealtime,
2
2
  /** @deprecated - please use useCedarRealtime instead */
3
- useRedwoodRealtime, createPubSub, liveDirectiveTypeDefs, InMemoryLiveQueryStore, RedisLiveQueryStore, liveQueryStore, pubSub, Repeater, } from './graphql';
3
+ useRedwoodRealtime, createPubSub, liveDirectiveTypeDefs, InMemoryLiveQueryStore, RedisLiveQueryStore, liveQueryStore, pubSub, Repeater, } from './graphql/plugins/useCedarRealtime';
4
4
  export type { LiveQueryStorageMechanism, PubSub, PublishClientType, SubscribeClientType, SubscriptionGlobImports, CedarRealtimeOptions,
5
5
  /** @deprecated - please use CedarRealtimeOptions instead */
6
- RedwoodRealtimeOptions, } from './graphql';
6
+ RedwoodRealtimeOptions, } from './graphql/plugins/useCedarRealtime';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB;AAChB,wDAAwD;AACxD,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,MAAM,EACN,QAAQ,GACT,MAAM,WAAW,CAAA;AAElB,YAAY,EACV,yBAAyB,EACzB,MAAM,EACN,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB;AACpB,4DAA4D;AAC5D,sBAAsB,GACvB,MAAM,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB;AAChB,wDAAwD;AACxD,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,MAAM,EACN,QAAQ,GACT,MAAM,oCAAoC,CAAA;AAE3C,YAAY,EACV,yBAAyB,EACzB,MAAM,EACN,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB;AACpB,4DAA4D;AAC5D,sBAAsB,GACvB,MAAM,oCAAoC,CAAA"}
package/dist/index.js CHANGED
@@ -1,173 +1,15 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- InMemoryLiveQueryStore: () => import_in_memory_live_query_store.InMemoryLiveQueryStore,
24
- RedisLiveQueryStore: () => RedisLiveQueryStore,
25
- Repeater: () => import_graphql_yoga.Repeater,
26
- createPubSub: () => import_subscription.createPubSub,
27
- liveDirectiveTypeDefs: () => liveDirectiveTypeDefs,
28
- liveQueryStore: () => liveQueryStore,
29
- pubSub: () => pubSub,
30
- useCedarRealtime: () => useCedarRealtime,
31
- useRedwoodRealtime: () => useRedwoodRealtime
32
- });
33
- module.exports = __toCommonJS(src_exports);
34
-
35
- // src/graphql/plugins/useCedarRealtime.ts
36
- var import_live_query = require("@envelop/live-query");
37
- var import_schema = require("@graphql-tools/schema");
38
- var import_utils = require("@graphql-tools/utils");
39
- var import_plugin_defer_stream = require("@graphql-yoga/plugin-defer-stream");
40
- var import_plugin_graphql_sse = require("@graphql-yoga/plugin-graphql-sse");
41
- var import_redis_event_target = require("@graphql-yoga/redis-event-target");
42
- var import_subscription = require("@graphql-yoga/subscription");
43
- var import_graphql_live_query = require("@n1ru4l/graphql-live-query");
44
- var import_in_memory_live_query_store = require("@n1ru4l/in-memory-live-query-store");
45
- var import_graphql = require("graphql");
46
- var import_graphql_yoga = require("graphql-yoga");
47
- var liveDirectiveTypeDefs = (0, import_graphql.print)(
48
- (0, import_utils.astFromDirective)(import_graphql_live_query.GraphQLLiveDirective)
49
- );
50
- var RedisLiveQueryStore = class {
51
- pub;
52
- sub;
53
- channel;
54
- liveQueryStore;
55
- constructor(pub, sub, channel, liveQueryStore2) {
56
- this.pub = pub;
57
- this.sub = sub;
58
- this.liveQueryStore = liveQueryStore2;
59
- this.channel = channel;
60
- this.sub.subscribe(this.channel, (err) => {
61
- if (err) {
62
- throw err;
63
- }
64
- });
65
- this.sub.on("message", (channel2, resourceIdentifier) => {
66
- if (channel2 === this.channel && resourceIdentifier) {
67
- this.liveQueryStore.invalidate(resourceIdentifier);
68
- }
69
- });
70
- }
71
- async invalidate(identifiers) {
72
- if (typeof identifiers === "string") {
73
- identifiers = [identifiers];
74
- }
75
- for (const identifier of identifiers) {
76
- this.pub.publish(this.channel, identifier);
77
- }
78
- }
79
- makeExecute(execute) {
80
- return this.liveQueryStore.makeExecute(execute);
81
- }
82
- };
83
- var liveQueryStore = void 0;
84
- var pubSub = void 0;
85
- var useCedarRealtime = (options) => {
86
- let liveQueriesEnabled = false;
87
- let subscriptionsEnabled = false;
88
- let liveQueryPlugin = {};
89
- const inMemoryLiveQueryStore = new import_in_memory_live_query_store.InMemoryLiveQueryStore();
90
- liveQueryStore = {};
91
- pubSub = {};
92
- const wasLiveQueryAdded = Symbol.for("useCedarRealtime.wasLiveQueryAdded");
93
- if (options.liveQueries?.store) {
94
- if (options.liveQueries.store === "in-memory") {
95
- liveQueriesEnabled = true;
96
- liveQueryStore = inMemoryLiveQueryStore;
97
- liveQueryPlugin = (0, import_live_query.useLiveQuery)({ liveQueryStore });
98
- } else if (options.liveQueries.store.redis) {
99
- liveQueriesEnabled = true;
100
- liveQueryStore = new RedisLiveQueryStore(
101
- options.liveQueries.store.redis.publishClient,
102
- options.liveQueries.store.redis.subscribeClient,
103
- options.liveQueries.store.redis.channel || "live-query-invalidations",
104
- inMemoryLiveQueryStore
105
- );
106
- liveQueryPlugin = (0, import_live_query.useLiveQuery)({
107
- liveQueryStore
108
- });
109
- } else {
110
- throw new Error("Invalid live query store configuration.");
111
- }
112
- }
113
- if (options.subscriptions?.store) {
114
- if (options.subscriptions.store === "in-memory") {
115
- subscriptionsEnabled = true;
116
- pubSub = (0, import_subscription.createPubSub)();
117
- } else if (options.subscriptions.store.redis) {
118
- subscriptionsEnabled = true;
119
- const eventTarget = (0, import_redis_event_target.createRedisEventTarget)({
120
- publishClient: options.subscriptions.store.redis.publishClient,
121
- subscribeClient: options.subscriptions.store.redis.subscribeClient
122
- });
123
- pubSub = (0, import_subscription.createPubSub)({ eventTarget });
124
- } else {
125
- throw new Error("Invalid subscriptions store configuration.");
126
- }
127
- }
128
- return {
129
- onSchemaChange({ replaceSchema, schema }) {
130
- if (schema.extensions?.[wasLiveQueryAdded] === true) {
131
- return;
132
- }
133
- if (liveQueriesEnabled) {
134
- const liveSchema = (0, import_schema.mergeSchemas)({
135
- schemas: [schema],
136
- typeDefs: [liveDirectiveTypeDefs]
137
- });
138
- liveSchema.extensions = {
139
- ...schema.extensions,
140
- [wasLiveQueryAdded]: true
141
- };
142
- replaceSchema(liveSchema);
143
- }
144
- },
145
- onPluginInit({ addPlugin }) {
146
- if (liveQueriesEnabled) {
147
- addPlugin(liveQueryPlugin);
148
- }
149
- if (subscriptionsEnabled) {
150
- addPlugin((0, import_plugin_graphql_sse.useGraphQLSSE)());
151
- }
152
- if (options.enableDeferStream) {
153
- addPlugin((0, import_plugin_defer_stream.useDeferStream)());
154
- }
155
- },
156
- onContextBuilding() {
157
- return ({ extendContext }) => {
158
- extendContext({
159
- liveQueryStore: liveQueriesEnabled && liveQueryStore,
160
- pubSub: subscriptionsEnabled && pubSub
161
- });
162
- };
163
- }
164
- };
165
- };
166
- var useRedwoodRealtime = (options) => {
167
- return useCedarRealtime(options);
168
- };
169
- // Annotate the CommonJS export names for ESM import in node:
170
- 0 && (module.exports = {
1
+ import {
2
+ useCedarRealtime,
3
+ useRedwoodRealtime,
4
+ createPubSub,
5
+ liveDirectiveTypeDefs,
6
+ InMemoryLiveQueryStore,
7
+ RedisLiveQueryStore,
8
+ liveQueryStore,
9
+ pubSub,
10
+ Repeater
11
+ } from "./graphql/plugins/useCedarRealtime";
12
+ export {
171
13
  InMemoryLiveQueryStore,
172
14
  RedisLiveQueryStore,
173
15
  Repeater,
@@ -177,4 +19,4 @@ var useRedwoodRealtime = (options) => {
177
19
  pubSub,
178
20
  useCedarRealtime,
179
21
  useRedwoodRealtime
180
- });
22
+ };
package/package.json CHANGED
@@ -1,21 +1,27 @@
1
1
  {
2
2
  "name": "@cedarjs/realtime",
3
- "version": "2.7.1-next.0+ef2bf2525",
3
+ "version": "2.7.1-next.34+fa909cc4d",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
7
7
  "directory": "packages/realtime"
8
8
  },
9
9
  "license": "MIT",
10
- "exports": "./dist/index.js",
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
11
17
  "types": "./dist/index.d.ts",
12
18
  "files": [
13
19
  "dist"
14
20
  ],
15
21
  "scripts": {
16
- "build": "tsx ./build.mts && run build:types",
22
+ "build": "node ./build.mts",
17
23
  "build:pack": "yarn pack -o cedarjs-realtime.tgz",
18
- "build:types": "tsc --build --verbose",
24
+ "build:types": "tsc --build --verbose ./tsconfig.build.json",
19
25
  "build:watch": "nodemon --watch src --ext \"js,ts,tsx\" --ignore dist --exec \"yarn build\"",
20
26
  "prepublishOnly": "NODE_ENV=production yarn build",
21
27
  "test": "vitest run",
@@ -31,13 +37,14 @@
31
37
  "@graphql-yoga/subscription": "5.0.5",
32
38
  "@n1ru4l/graphql-live-query": "0.10.0",
33
39
  "@n1ru4l/in-memory-live-query-store": "0.10.0",
34
- "graphql": "16.13.0"
40
+ "graphql": "16.13.1"
35
41
  },
36
42
  "devDependencies": {
37
- "@cedarjs/framework-tools": "2.7.1-next.1",
43
+ "@cedarjs/framework-tools": "2.7.1-next.34",
38
44
  "@envelop/core": "5.5.1",
39
45
  "@envelop/testing": "7.0.0",
40
46
  "@envelop/types": "5.2.1",
47
+ "graphql-yoga": "5.18.0",
41
48
  "ioredis": "5.10.0",
42
49
  "nodemon": "3.1.14",
43
50
  "tsx": "4.21.0",
@@ -55,5 +62,5 @@
55
62
  "publishConfig": {
56
63
  "access": "public"
57
64
  },
58
- "gitHead": "ef2bf2525e8fbeada576b4bab5d1b4b358354ae0"
65
+ "gitHead": "fa909cc4dd4ffad00a53339db7cc3d2be499b936"
59
66
  }
@@ -1,7 +0,0 @@
1
- export { useCedarRealtime,
2
- /** @deprecated - please use useCedarRealtime instead */
3
- useRedwoodRealtime, createPubSub, liveDirectiveTypeDefs, InMemoryLiveQueryStore, RedisLiveQueryStore, liveQueryStore, pubSub, Repeater, } from './plugins/useCedarRealtime';
4
- export type { LiveQueryStorageMechanism, PubSub, PublishClientType, SubscribeClientType, SubscriptionGlobImports, CedarRealtimeOptions,
5
- /** @deprecated - please use CedarRealtimeOptions instead */
6
- RedwoodRealtimeOptions, } from './plugins/useCedarRealtime';
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/graphql/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB;AAChB,wDAAwD;AACxD,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,MAAM,EACN,QAAQ,GACT,MAAM,4BAA4B,CAAA;AAEnC,YAAY,EACV,yBAAyB,EACzB,MAAM,EACN,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB;AACpB,4DAA4D;AAC5D,sBAAsB,GACvB,MAAM,4BAA4B,CAAA"}
@@ -1,9 +0,0 @@
1
- export declare const testSchema: import("graphql").GraphQLSchema;
2
- export declare const testLiveSchema: import("graphql").GraphQLSchema;
3
- export declare const testQuery = "\n query meQuery {\n me {\n id\n name\n }\n }\n";
4
- export declare const testFilteredQuery = "\n query FilteredQuery {\n me {\n id\n name\n }\n }\n";
5
- export declare const testErrorQuery = "\n query forbiddenUserQuery {\n forbiddenUser {\n id\n name\n }\n }\n";
6
- export declare const testLiveQuery = "\n query meQuery @live {\n me {\n id\n name\n }\n }\n";
7
- export declare const testParseErrorQuery = "\n query ParseErrorQuery {\n me {\n id\n name\n unknown_field\n }\n }\n";
8
- export declare const testValidationErrorQuery = "\n query ValidationErrorQuery(id: Int!) {\n getUser(id: 'one') {\n id\n name\n }\n }\n";
9
- //# sourceMappingURL=common.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/graphql/plugins/__fixtures__/common.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,iCAiCrB,CAAA;AAEF,eAAO,MAAM,cAAc,iCAgDzB,CAAA;AACF,eAAO,MAAM,SAAS,sEAOrB,CAAA;AAED,eAAO,MAAM,iBAAiB,4EAO7B,CAAA;AAED,eAAO,MAAM,cAAc,4FAO1B,CAAA;AAED,eAAO,MAAM,aAAa,4EAOzB,CAAA;AAED,eAAO,MAAM,mBAAmB,mGAQ/B,CAAA;AAED,eAAO,MAAM,wBAAwB,6GAOpC,CAAA"}