@mintlify/common 1.0.1191 → 1.0.1193
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/graphql/index.d.ts +2 -0
- package/dist/graphql/index.js +2 -0
- package/dist/graphql/parseGraphqlSelector.d.ts +6 -0
- package/dist/graphql/parseGraphqlSelector.js +15 -0
- package/dist/graphql/resolveGraphqlOperation.d.ts +7 -0
- package/dist/graphql/resolveGraphqlOperation.js +21 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const GRAPHQL_NAME = /^[_A-Za-z][_0-9A-Za-z]*$/;
|
|
2
|
+
const SELECTOR_KINDS = ['query', 'mutation', 'type'];
|
|
3
|
+
export const parseGraphqlSelector = (str) => {
|
|
4
|
+
const [rawKind, name, ...extra] = str.trim().split(/\s+/);
|
|
5
|
+
if (!rawKind || !name || extra.length > 0)
|
|
6
|
+
return undefined;
|
|
7
|
+
const kind = SELECTOR_KINDS.find((kind) => kind.toUpperCase() === rawKind);
|
|
8
|
+
if (!kind)
|
|
9
|
+
return undefined;
|
|
10
|
+
if (kind === 'type' && name.includes('.'))
|
|
11
|
+
return undefined;
|
|
12
|
+
if (!name.split('.').every((segment) => GRAPHQL_NAME.test(segment)))
|
|
13
|
+
return undefined;
|
|
14
|
+
return { kind, name };
|
|
15
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GraphqlField, GraphqlReference, GraphqlTarget, GraphqlTypeRef } from '@mintlify/models';
|
|
2
|
+
export declare const getNamedGraphqlType: (type: GraphqlTypeRef) => string;
|
|
3
|
+
export type ResolvedGraphqlOperation = {
|
|
4
|
+
field: GraphqlField;
|
|
5
|
+
parents: GraphqlField[];
|
|
6
|
+
};
|
|
7
|
+
export declare const resolveGraphqlOperation: (reference: GraphqlReference, target: Pick<GraphqlTarget, "kind" | "name">) => ResolvedGraphqlOperation | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const getNamedGraphqlType = (type) => type.kind === 'named' ? type.name : getNamedGraphqlType(type.ofType);
|
|
2
|
+
export const resolveGraphqlOperation = (reference, target) => {
|
|
3
|
+
if (target.kind !== 'query' && target.kind !== 'mutation')
|
|
4
|
+
return undefined;
|
|
5
|
+
let typeName = target.kind === 'query' ? reference.queryType : reference.mutationType;
|
|
6
|
+
const path = [];
|
|
7
|
+
for (const segment of target.name.split('.')) {
|
|
8
|
+
const type = reference.types.find(({ name }) => name === typeName);
|
|
9
|
+
if ((type === null || type === void 0 ? void 0 : type.kind) !== 'object' && (type === null || type === void 0 ? void 0 : type.kind) !== 'interface')
|
|
10
|
+
return undefined;
|
|
11
|
+
const field = type.fields.find(({ name }) => name === segment);
|
|
12
|
+
if (!field)
|
|
13
|
+
return undefined;
|
|
14
|
+
path.push(field);
|
|
15
|
+
typeName = getNamedGraphqlType(field.type);
|
|
16
|
+
}
|
|
17
|
+
const field = path.pop();
|
|
18
|
+
if (!field)
|
|
19
|
+
return undefined;
|
|
20
|
+
return { field, parents: path };
|
|
21
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export * from './title.js';
|
|
|
18
18
|
export * from './schema/common.js';
|
|
19
19
|
export * from './camelToSentenceCase.js';
|
|
20
20
|
export * from './asyncapi/index.js';
|
|
21
|
+
export * from './graphql/index.js';
|
|
21
22
|
export * from './isAbsoluteUrl.js';
|
|
22
23
|
export * from './isValidEmail.js';
|
|
23
24
|
export * from './rss/index.js';
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export * from './title.js';
|
|
|
18
18
|
export * from './schema/common.js';
|
|
19
19
|
export * from './camelToSentenceCase.js';
|
|
20
20
|
export * from './asyncapi/index.js';
|
|
21
|
+
export * from './graphql/index.js';
|
|
21
22
|
export * from './isAbsoluteUrl.js';
|
|
22
23
|
export * from './isValidEmail.js';
|
|
23
24
|
export * from './rss/index.js';
|