@conduit-client/onestore-graphql-parser 3.14.0 → 3.15.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.
- package/dist/types/v1/bindings-utils.d.ts +2 -1
- package/dist/types/v1/gql.d.ts +28 -6
- package/dist/types/v1/index.d.ts +1 -1
- package/dist/v1/index.js +12 -23
- package/dist/v1/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Result } from '@conduit-client/utils';
|
|
2
|
+
import { type ParsedGraphQLDocument } from './gql';
|
|
2
3
|
import type { DocumentNode } from 'graphql/language';
|
|
3
4
|
import type { GraphQLResponse } from './types';
|
|
4
5
|
/**
|
|
@@ -16,7 +17,7 @@ export type ResolveAndValidateOptions = {
|
|
|
16
17
|
acceptedOperations?: ('query' | 'mutation' | 'subscription')[];
|
|
17
18
|
};
|
|
18
19
|
export type UnverifiedGraphQLConfig = {
|
|
19
|
-
query?:
|
|
20
|
+
query?: ParsedGraphQLDocument;
|
|
20
21
|
operationName?: string;
|
|
21
22
|
variables?: Record<string, unknown>;
|
|
22
23
|
};
|
package/dist/types/v1/gql.d.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import type { DefinitionNode, DocumentNode } from 'graphql/language';
|
|
2
2
|
import type { GraphQLResponse } from './types';
|
|
3
|
+
declare const __brand: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* Compile-time-only branded type. Intersects a base type `T` with a phantom property
|
|
6
|
+
* keyed by a unique symbol, preventing structurally identical types from being assigned
|
|
7
|
+
* to one another. The brand property has no runtime representation.
|
|
8
|
+
*/
|
|
9
|
+
type Opaque<T, B> = T & {
|
|
10
|
+
readonly [__brand]: B;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Opaque branded type returned by `gql`.
|
|
14
|
+
* Consumers cannot construct this directly -- it can only be obtained from the `gql` tag / function.
|
|
15
|
+
* Pass it as `query` in adapter config types for type-safe GraphQL resolution.
|
|
16
|
+
*/
|
|
17
|
+
export type ParsedGraphQLDocument = Opaque<unknown, 'ParsedGraphQLDocument'>;
|
|
3
18
|
export type AstResolution = {
|
|
4
19
|
type: 'document';
|
|
5
20
|
document: DocumentNode;
|
|
@@ -23,9 +38,9 @@ export declare const referenceMap: WeakMap<Object, AstResolution>;
|
|
|
23
38
|
* @param inputString - operation string
|
|
24
39
|
* @returns DocumentNode or GraphQLResponse with errors if parsing fails
|
|
25
40
|
*/
|
|
26
|
-
export declare function parseDocument(inputString: string): AstResolution
|
|
41
|
+
export declare function parseDocument(inputString: string): AstResolution;
|
|
27
42
|
export declare function updateReferenceMapWithKnownKey(doc: AstResolution, key: object): void;
|
|
28
|
-
export declare function updateReferenceMapAndGetKey(doc: AstResolution):
|
|
43
|
+
export declare function updateReferenceMapAndGetKey(doc: AstResolution): ParsedGraphQLDocument;
|
|
29
44
|
/**
|
|
30
45
|
* Insert string and fragment substitutions with the actual nodes
|
|
31
46
|
* @param inputString
|
|
@@ -42,9 +57,16 @@ export declare function processSubstitutions(inputString: ReadonlyArray<string>,
|
|
|
42
57
|
*/
|
|
43
58
|
export declare const astResolver: AstResolver;
|
|
44
59
|
/**
|
|
60
|
+
* Tagged template literal (or callable function) that parses a GraphQL operation string.
|
|
61
|
+
*
|
|
62
|
+
* Always returns an opaque {@link ParsedGraphQLDocument} reference -- even when parsing fails.
|
|
63
|
+
* A returned reference does **not** indicate successful parsing. Parsing errors are deferred
|
|
64
|
+
* until the adapter resolves the reference, at which point a `GraphQLErrors`-shaped response
|
|
65
|
+
* is emitted to the consumer.
|
|
45
66
|
*
|
|
46
|
-
* @param literals - operation query string
|
|
47
|
-
* @param subs -
|
|
48
|
-
* @returns an opaque reference
|
|
67
|
+
* @param literals - operation query string (or template literal strings array)
|
|
68
|
+
* @param subs - template literal substitutions (strings or fragment references from other `gql` calls)
|
|
69
|
+
* @returns an opaque reference that can be passed as `query` in adapter config types
|
|
49
70
|
*/
|
|
50
|
-
export declare function gql(literals: ReadonlyArray<string> | string, ...subs: (string | object)[]):
|
|
71
|
+
export declare function gql(literals: ReadonlyArray<string> | string, ...subs: (string | object)[]): ParsedGraphQLDocument;
|
|
72
|
+
export {};
|
package/dist/types/v1/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export type { GraphQLObjectType, GraphQLInterfaceType, GraphQLDirective, GraphQL
|
|
|
2
2
|
export type { ASTNode, ObjectValueNode, ListTypeNode, BooleanValueNode, EnumTypeDefinitionNode, FieldDefinitionNode, FloatValueNode, InterfaceTypeDefinitionNode, IntValueNode, NamedTypeNode, ObjectTypeDefinitionNode, StringValueNode, TypeNode, UnionTypeDefinitionNode, DocumentNode, OperationDefinitionNode, FieldNode, ArgumentNode, ValueNode, SelectionNode, SelectionSetNode, FragmentDefinitionNode, DirectiveNode, ObjectFieldNode, ScalarTypeDefinitionNode, InputObjectTypeDefinitionNode, InlineFragmentNode, FragmentSpreadNode, VariableDefinitionNode, ListValueNode, VariableNode, NullValueNode, } from 'graphql/language';
|
|
3
3
|
export { Kind } from 'graphql/language';
|
|
4
4
|
export { gql, astResolver } from './gql';
|
|
5
|
-
export type { AstResolver, AstResolution } from './gql';
|
|
5
|
+
export type { AstResolver, AstResolution, ParsedGraphQLDocument } from './gql';
|
|
6
6
|
export { parse, print, visit } from 'graphql/language';
|
|
7
7
|
export type { ResolveAndValidateOptions, UnverifiedGraphQLConfig, ValidGraphQLConfig, } from './bindings-utils';
|
|
8
8
|
export { resolveAndValidateGraphQLConfig } from './bindings-utils';
|
package/dist/v1/index.js
CHANGED
|
@@ -3112,6 +3112,12 @@ function updateReferenceMapAndGetKey(doc) {
|
|
|
3112
3112
|
updateReferenceMapWithKnownKey(doc, key);
|
|
3113
3113
|
return key;
|
|
3114
3114
|
}
|
|
3115
|
+
function createErrorRef(message) {
|
|
3116
|
+
return updateReferenceMapAndGetKey({
|
|
3117
|
+
type: "error",
|
|
3118
|
+
error: { errors: [{ message }] }
|
|
3119
|
+
});
|
|
3120
|
+
}
|
|
3115
3121
|
function processSubstitutions(inputString, substitutions) {
|
|
3116
3122
|
let outputString = "";
|
|
3117
3123
|
const fragments = [];
|
|
@@ -3123,21 +3129,13 @@ function processSubstitutions(inputString, substitutions) {
|
|
|
3123
3129
|
outputString += substitution;
|
|
3124
3130
|
} else if (typeof substitution === "object") {
|
|
3125
3131
|
const resolved = referenceMap.get(substitution);
|
|
3126
|
-
if (resolved === void 0) {
|
|
3127
|
-
if (process.env.NODE_ENV !== "production") {
|
|
3128
|
-
throw new Error("Invalid substitution fragment");
|
|
3129
|
-
}
|
|
3132
|
+
if (resolved === void 0 || resolved.type === "error") {
|
|
3130
3133
|
return null;
|
|
3131
3134
|
}
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
fragments.push(def);
|
|
3135
|
-
}
|
|
3135
|
+
for (const def of resolved.document.definitions) {
|
|
3136
|
+
fragments.push(def);
|
|
3136
3137
|
}
|
|
3137
3138
|
} else {
|
|
3138
|
-
if (process.env.NODE_ENV !== "production") {
|
|
3139
|
-
throw new Error("Unsupported substitution type");
|
|
3140
|
-
}
|
|
3141
3139
|
return null;
|
|
3142
3140
|
}
|
|
3143
3141
|
}
|
|
@@ -3156,32 +3154,23 @@ function gql(literals, ...subs) {
|
|
|
3156
3154
|
let inputString;
|
|
3157
3155
|
let inputSubstitutionFragments;
|
|
3158
3156
|
if (!literals) {
|
|
3159
|
-
|
|
3160
|
-
throw new Error("Invalid query");
|
|
3161
|
-
}
|
|
3162
|
-
return null;
|
|
3157
|
+
return createErrorRef("Invalid query");
|
|
3163
3158
|
} else if (typeof literals === "string") {
|
|
3164
3159
|
inputString = literals.trim();
|
|
3165
3160
|
inputSubstitutionFragments = [];
|
|
3166
3161
|
} else {
|
|
3167
3162
|
const sub = processSubstitutions(literals, subs);
|
|
3168
3163
|
if (sub === null) {
|
|
3169
|
-
return
|
|
3164
|
+
return createErrorRef("Invalid substitution");
|
|
3170
3165
|
}
|
|
3171
3166
|
const { operationString, fragments } = sub;
|
|
3172
3167
|
inputString = operationString.trim();
|
|
3173
3168
|
inputSubstitutionFragments = fragments;
|
|
3174
3169
|
}
|
|
3175
3170
|
if (inputString.length === 0) {
|
|
3176
|
-
|
|
3177
|
-
throw new Error("Invalid query");
|
|
3178
|
-
}
|
|
3179
|
-
return null;
|
|
3171
|
+
return createErrorRef("Invalid query");
|
|
3180
3172
|
}
|
|
3181
3173
|
const document = parseDocument(inputString);
|
|
3182
|
-
if (document === null) {
|
|
3183
|
-
return null;
|
|
3184
|
-
}
|
|
3185
3174
|
if (document.type === "error") {
|
|
3186
3175
|
return updateReferenceMapAndGetKey(document);
|
|
3187
3176
|
}
|