-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathNuxtGraphQLSchema.ts
More file actions
53 lines (45 loc) · 2.06 KB
/
Copy pathNuxtGraphQLSchema.ts
File metadata and controls
53 lines (45 loc) · 2.06 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
51
52
53
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
import NotAuthorizedResponse from "@webiny/api-core/graphql/security/NotAuthorizedResponse.js";
import { ErrorResponse, Response } from "@webiny/handler-graphql";
import { CoreGraphQLSchemaFactory } from "@webiny/handler-graphql/graphql/abstractions.core.js";
import { NuxtConfig } from "~/features/nuxt/index.js";
import { GraphQLSchemaBuilder } from "@webiny/handler-graphql/features/GraphQLSchemaBuilder/abstractions.js";
class Schema implements CoreGraphQLSchemaFactory.Interface {
public async execute(builder: GraphQLSchemaBuilder.Interface): CoreGraphQLSchemaFactory.Return {
builder.addTypeDefs(/* GraphQL */ `
type NuxtConfigResponse {
data: String
error: WbError
}
extend type WbQuery {
getNuxtConfig: NuxtConfigResponse
}
`);
builder.addResolver({
dependencies: [IdentityContext, NuxtConfig],
path: "WbQuery.getNuxtConfig",
resolver(identityContext: IdentityContext.Interface, nuxtConfig: NuxtConfig.Interface) {
return async () => {
const identity = identityContext.getIdentity();
if (!identity.isAdmin()) {
return new NotAuthorizedResponse();
}
const permission = await identityContext.getPermission("wb.settings");
if (!permission) {
return new ErrorResponse({
code: "WebsiteBuilder/Settings/NotAuthorized",
message: "Not authorized!"
});
}
const config = await nuxtConfig.execute();
return new Response(config.build());
};
}
});
return builder;
}
}
export const NuxtGraphQLSchema = CoreGraphQLSchemaFactory.createImplementation({
implementation: Schema,
dependencies: []
});