-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathresources.ts
More file actions
33 lines (26 loc) · 848 Bytes
/
resources.ts
File metadata and controls
33 lines (26 loc) · 848 Bytes
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
import type { ObjectTypeDefinitionNode, TypeNode } from "graphql";
import Resource from "./resource.ts";
import { unwrapCompositeType } from "./utils.ts";
export default class Resources {
all: Array<Resource>;
constructor(resourceTypeDefs: ObjectTypeDefinitionNode[]) {
this.all = resourceTypeDefs.map((def) =>
Resource.buildFromTypeDefinition(this, def)
);
}
get root(): Array<Resource> {
return this.all.filter((resource) => resource.isRootType);
}
lookup(name: string): Resource | null {
return (
this.all.find((resource) => resource.definition.name.value === name) ||
null
);
}
isUserDefined(type: TypeNode): boolean {
const unwrapped = unwrapCompositeType(type);
return this.all.some(
(resource) => resource.definition.name.value === unwrapped.name.value
);
}
}