-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmesh.config.ts
More file actions
50 lines (42 loc) · 1.35 KB
/
Copy pathmesh.config.ts
File metadata and controls
50 lines (42 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { defineConfig } from "@graphql-mesh/compose-cli";
import { loadOpenAPISubgraph } from "@omnigraph/openapi";
import "dotenv";
import { GraphQLSchema, GraphQLString, getNamedType, isEnumType } from "graphql";
import { mapSchema, MapperKind } from "@graphql-tools/utils";
const PORT = process.env.PORT || "3005";
export const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: loadOpenAPISubgraph("Laji-API", {
source: `http://localhost:${PORT}/openapi-json`,
operationHeaders: {
"Accept": "application/json",
},
ignoreErrorResponses: true,
}),
transforms: [
// We do this because GraphQL enums don't allow dot character in enums. The generated schema would have the
// enums with dots replaced with lower dash. Our enums have dots (like `MY.collectionQuality`), and we want to
// keep them to keep ids stable.
replaceEnumsWithStrings
]
}
],
});
export function replaceEnumsWithStrings(schema: GraphQLSchema) {
return mapSchema(schema, {
[MapperKind.OBJECT_FIELD]: (fieldConfig) => {
const namedType = getNamedType(fieldConfig.type);
if (!isEnumType(namedType)) {
return fieldConfig;
}
fieldConfig.type = GraphQLString;
const source =
(fieldConfig.extensions as any)?.directives?.source;
if (source?.type) {
source.type = "String";
}
return fieldConfig;
},
});
}