Skip to content

Commit 01360f1

Browse files
committed
chore: goodbye ramda 😅
1 parent 425fd45 commit 01360f1

File tree

4 files changed

+63
-35
lines changed

4 files changed

+63
-35
lines changed

package-lock.json

Lines changed: 1 addition & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
"@graphql-tools/graphql-file-loader": "^7.5.17",
3535
"@graphql-tools/load": "^7.8.14",
3636
"graphql": "^16.6.0",
37-
"lodash": "4.17.21",
38-
"ramda": "^0.29.0"
37+
"lodash": "4.17.21"
3938
},
4039
"devDependencies": {
4140
"@types/eslint": "^8.21.1",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import stringify from "safe-stable-stringify";
55
const parsedSchema = new schemaParser("schema/schema.graphql");
66

77
// Dump stringified schema
8-
console.log(stringify(parsedSchema));
8+
// console.log(stringify(parsedSchema));
99

1010
// Dump a type
1111
console.log(parsedSchema.getTypename("Author"));

src/introspection/introspection.ts

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import _ from "lodash";
2-
import * as R from "ramda";
1+
import _, { map, shuffle } from "lodash";
32

43
import {
54
GraphQLNamedType,
@@ -16,6 +15,16 @@ import {
1615
isInterfaceType,
1716
isScalarType,
1817
SingleFieldSubscriptionsRule,
18+
GraphQLEnumType,
19+
GraphQLInputObjectType,
20+
GraphQLInputType,
21+
GraphQLInterfaceType,
22+
GraphQLList,
23+
GraphQLNonNull,
24+
GraphQLObjectType,
25+
GraphQLOutputType,
26+
GraphQLScalarType,
27+
GraphQLUnionType,
1928
} from "graphql";
2029
import {
2130
SimplifiedIntrospection,
@@ -26,7 +35,31 @@ import {
2635
} from "./types.js";
2736
import { typeNameToId } from "./utils.js";
2837

29-
function unwrapType(type) {
38+
function unwrapType(
39+
type:
40+
| GraphQLScalarType<unknown, unknown>
41+
| GraphQLEnumType
42+
| GraphQLInputObjectType
43+
| GraphQLList<GraphQLInputType>
44+
| GraphQLNonNull<
45+
| GraphQLEnumType
46+
| GraphQLInputObjectType
47+
| GraphQLScalarType<unknown, unknown>
48+
| GraphQLList<GraphQLInputType>
49+
>
50+
| GraphQLInterfaceType
51+
| GraphQLUnionType
52+
| GraphQLObjectType<any, any>
53+
| GraphQLList<GraphQLOutputType>
54+
| GraphQLNonNull<
55+
| GraphQLEnumType
56+
| GraphQLInterfaceType
57+
| GraphQLUnionType
58+
| GraphQLScalarType<unknown, unknown>
59+
| GraphQLObjectType<any, any>
60+
| GraphQLList<GraphQLOutputType>
61+
>
62+
) {
3063
let unwrappedType = type;
3164
const typeWrappers = [];
3265

@@ -214,46 +247,52 @@ function addParent(schema: SimplifiedIntrospection) {
214247
if (type.type === "[Circular]") return [type];
215248

216249
// same with scalars and enums
217-
if (R.includes(type.kind && type.kind, ["SCALAR", "ENUM"])) return [];
250+
if (_.includes(["SCALAR", "ENUM"], type.kind && type.kind)) return [];
218251
if (
219252
type.type &&
220253
type.type.kind &&
221-
R.includes(type.type.kind, ["SCALAR", "ENUM"])
254+
_.includes(["SCALAR", "ENUM"], type.type.kind)
222255
)
223256
return [];
224257

225-
return R.chain((currentType) => {
258+
return _.flatMap(_.values(type.fields), (currentType) => {
226259
// if it's a composite object, use recursion to introspect the inner object
227260
const innerTypes = currentType.type.fields
228-
? R.chain((subType) => extractFields(subType), currentType.type.fields)
261+
? _.flatMap(currentType.type.fields, (subType) =>
262+
extractFields(subType)
263+
)
229264
: [currentType];
230265
// dedupe types by their id
231-
return R.uniqBy((x) => x.id, R.append(currentType, innerTypes));
232-
}, R.values(type.fields));
266+
return _.uniqBy(_.concat(innerTypes, currentType), (x) => x.id);
267+
});
233268
}
234269

235-
const allFields = R.chain(
236-
(type) => extractFields(type),
237-
R.values(schema.types)
270+
const allFields = _.flatMap(_.values(schema.types), (type) =>
271+
extractFields(type)
238272
);
239273

240274
/*
241275
* Group fields by their corresponding type id
242276
*/
277+
const groupedFieldsByType = _.groupBy(allFields, function (field) {
278+
return field.type.id;
279+
});
243280

281+
/*
282+
* Extract id and prepare the mapping
283+
*/
284+
const mappings = _.mapValues(groupedFieldsByType, function (t) {
285+
return _.map(t, (field) => field.id);
286+
});
244287

245-
const mappings = R.map (
246-
x => R.map(y => y.id, x),
247-
R.groupBy(function (field) {
248-
return field.type.id;
249-
}, allFields)
250-
);
251-
252-
R.forEach(type => {
288+
/*
289+
* Assign the mapping
290+
*/
291+
_.each(Object.keys(schema.types), (type) => {
253292
if (mappings[type]) {
254293
(schema.types[type] as any).parents = mappings[type];
255294
}
256-
}, R.keys(schema.types));
295+
});
257296
}
258297

259298
export function getSchema(schema: GraphQLSchema) {

0 commit comments

Comments
 (0)