buro26-strapi-graphql 0.0.23 → 0.0.25
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/README.md +24 -1
- package/dist/server/bootstrap.d.ts +1 -1
- package/dist/server/controllers/index.d.ts +1 -1
- package/dist/server/controllers/my-controller.d.ts +1 -1
- package/dist/server/destroy.d.ts +1 -1
- package/dist/server/index.d.ts +12 -8
- package/dist/server/services/file-service.d.ts +1 -2
- package/dist/server/services/graphql-service.d.ts +1 -1
- package/dist/server/services/index.d.ts +2 -2
- package/dist/server/types.d.ts +2 -2
- package/dist/server/utils/collection-type.d.ts +2 -2
- package/dist/server/utils/collection-type.js +3 -3
- package/dist/server/utils/index.d.ts +1 -0
- package/dist/server/utils/index.js +1 -0
- package/dist/server/utils/shadow-crud.d.ts +30 -0
- package/dist/server/utils/shadow-crud.js +8 -0
- package/dist/server/utils/types.d.ts +2 -3
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +39 -45
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@ as co-location of GraphQL schema and resolvers, field overriding, and field auth
|
|
|
6
6
|
This let's you define your GraphQL schema and resolvers in the content-type directory, making it easier to manage and
|
|
7
7
|
maintain your GraphQL API.
|
|
8
8
|
|
|
9
|
+
This plugin is compatible with both Strapi v4 and Strapi v5.
|
|
10
|
+
|
|
9
11
|
## Getting started
|
|
10
12
|
|
|
11
13
|
```bash
|
|
@@ -21,7 +23,7 @@ the [Strapi GraphQL plugin](https://docs.strapi.io/dev-docs/plugins/graphql).
|
|
|
21
23
|
|
|
22
24
|
### Enable plugin
|
|
23
25
|
|
|
24
|
-
Add plugin in `./config/plugins.js/ts` in your Strapi project.
|
|
26
|
+
Add plugin in `./config/plugins.[js/ts]` in your Strapi project.
|
|
25
27
|
|
|
26
28
|
```typescript
|
|
27
29
|
export default () => ({
|
|
@@ -487,6 +489,27 @@ args into args that can be passed to the entityManager.
|
|
|
487
489
|
|
|
488
490
|
This function is re-exported from the Strapi GraphQL plugin.
|
|
489
491
|
|
|
492
|
+
#### shadowCRUD
|
|
493
|
+
|
|
494
|
+
This function is a typesafe utility function to create shadow CRUD operations for a content type. It will create the CRUD operations for the content type and return the shadow CRUD object.
|
|
495
|
+
|
|
496
|
+
```typescript
|
|
497
|
+
import { createGraphQLExtension, shadowCRUD } from 'buro26-strapi-graphql';
|
|
498
|
+
|
|
499
|
+
export default createGraphQLExtension((strapi) => ({
|
|
500
|
+
|
|
501
|
+
init() {
|
|
502
|
+
shadowCRUD('api::article.article')
|
|
503
|
+
.disableActions(['create', 'update', 'delete']);
|
|
504
|
+
|
|
505
|
+
shadowCRUD('api::category.category')
|
|
506
|
+
.field('title')
|
|
507
|
+
.disable();
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
}));
|
|
511
|
+
```
|
|
512
|
+
|
|
490
513
|
## Test and Deploy
|
|
491
514
|
|
|
492
515
|
### Running tests
|
package/dist/server/destroy.d.ts
CHANGED
package/dist/server/index.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import type { Strapi } from '
|
|
2
|
-
import type { GraphQLExtension } from './types';
|
|
1
|
+
import type { GraphQLExtension, Strapi } from './types';
|
|
3
2
|
import type { Middleware, ResolveContext } from './utils';
|
|
4
3
|
import type { GraphQLResolveInfo } from 'graphql';
|
|
5
4
|
import type { GraphQLFieldConfig } from 'graphql/type';
|
|
6
5
|
declare const _default: {
|
|
7
6
|
register: ({ strapi }: {
|
|
8
|
-
strapi: Strapi;
|
|
7
|
+
strapi: import("@strapi/types").Strapi;
|
|
9
8
|
}) => Promise<void>;
|
|
10
9
|
bootstrap: ({ strapi }: {
|
|
11
|
-
strapi: Strapi
|
|
10
|
+
strapi: Required<import("@strapi/types").Strapi>;
|
|
12
11
|
}) => void;
|
|
13
12
|
destroy: ({ strapi }: {
|
|
14
|
-
strapi: Strapi
|
|
13
|
+
strapi: Required<import("@strapi/types").Strapi>;
|
|
15
14
|
}) => void;
|
|
16
15
|
config: {
|
|
17
16
|
default: {};
|
|
@@ -19,18 +18,18 @@ declare const _default: {
|
|
|
19
18
|
};
|
|
20
19
|
controllers: {
|
|
21
20
|
myController: ({ strapi }: {
|
|
22
|
-
strapi: Strapi
|
|
21
|
+
strapi: Required<import("@strapi/types").Strapi>;
|
|
23
22
|
}) => {};
|
|
24
23
|
};
|
|
25
24
|
routes: any[];
|
|
26
25
|
services: {
|
|
27
26
|
fileService: ({ strapi }: {
|
|
28
|
-
strapi: Strapi
|
|
27
|
+
strapi: Required<import("@strapi/types").Strapi>;
|
|
29
28
|
}) => {
|
|
30
29
|
getAllFilesInGraphQlDirectory(directoryPath: string, collectedExtensions?: GraphQLExtension[]): Promise<GraphQLExtension[]>;
|
|
31
30
|
};
|
|
32
31
|
graphQlService: ({ strapi }: {
|
|
33
|
-
strapi: Strapi
|
|
32
|
+
strapi: Required<import("@strapi/types").Strapi>;
|
|
34
33
|
}) => {};
|
|
35
34
|
};
|
|
36
35
|
contentTypes: {};
|
|
@@ -46,6 +45,11 @@ declare module '@strapi/strapi' {
|
|
|
46
45
|
createGraphQLExtension: (factory: (strapi: Strapi) => GraphQLExtension) => GraphQLExtension;
|
|
47
46
|
}
|
|
48
47
|
}
|
|
48
|
+
declare module '@strapi/types' {
|
|
49
|
+
interface Strapi {
|
|
50
|
+
createGraphQLExtension: (factory: (strapi: Strapi) => GraphQLExtension) => GraphQLExtension;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
49
53
|
/**
|
|
50
54
|
* Extend Nexus's field definition to include a middleware array.
|
|
51
55
|
*/
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
fileService: ({ strapi }: {
|
|
3
|
-
strapi: import("@strapi/types").Strapi
|
|
3
|
+
strapi: Required<import("@strapi/types").Strapi>;
|
|
4
4
|
}) => {
|
|
5
5
|
getAllFilesInGraphQlDirectory(directoryPath: string, collectedExtensions?: import("..").GraphQLExtension[]): Promise<import("..").GraphQLExtension[]>;
|
|
6
6
|
};
|
|
7
7
|
graphQlService: ({ strapi }: {
|
|
8
|
-
strapi: import("@strapi/types").Strapi
|
|
8
|
+
strapi: Required<import("@strapi/types").Strapi>;
|
|
9
9
|
}) => {};
|
|
10
10
|
};
|
|
11
11
|
export default _default;
|
package/dist/server/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ResolveContext } from './utils';
|
|
2
2
|
import type { GraphQLResolveInfo } from 'graphql';
|
|
3
|
-
|
|
3
|
+
export type Strapi = typeof strapi;
|
|
4
4
|
export interface GraphQLExtension {
|
|
5
5
|
/**
|
|
6
6
|
* Called when the extension is initialized, use this to perform any initialization logic
|
|
@@ -55,7 +55,7 @@ export interface GraphQLExtension {
|
|
|
55
55
|
}
|
|
56
56
|
type ResolverConfigOption = {
|
|
57
57
|
auth?: boolean | undefined;
|
|
58
|
-
policies?: string
|
|
58
|
+
policies?: (string | PolicyFunction)[];
|
|
59
59
|
middlewares?: MiddlewareFunction[];
|
|
60
60
|
};
|
|
61
61
|
type PolicyFunctionContext = {
|
|
@@ -26,8 +26,8 @@ type EntityResponseCollection<T extends Object> = {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
type ExtractRelation<Parent, K extends keyof Parent> = Parent[K] extends Array<infer U> ? U extends object ? U : never : Parent[K] extends object ? Parent[K] : never;
|
|
29
|
-
export
|
|
29
|
+
export declare function toEntityResponseCollection<T extends Object>(items: T[], { args, resourceUID }: {
|
|
30
30
|
args: Record<string, any>;
|
|
31
31
|
resourceUID: string;
|
|
32
|
-
}): EntityResponseCollection<T
|
|
32
|
+
}): Promise<EntityResponseCollection<T>>;
|
|
33
33
|
export {};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Based on node_modules/@strapi/plugin-graphql/server/services/builders/resolvers/association.js
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.createEntityRelationCollectionResolver = exports.createEntityCollectionResolver = void 0;
|
|
8
|
+
exports.toEntityResponseCollection = exports.createEntityRelationCollectionResolver = exports.createEntityCollectionResolver = void 0;
|
|
9
9
|
/**
|
|
10
10
|
* Create a resolver for a collection of entities
|
|
11
11
|
* Returns a resolver that resolves the entities based on the content type UID
|
|
@@ -52,11 +52,11 @@ function createEntityRelationCollectionResolver(contentType) {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
exports.createEntityRelationCollectionResolver = createEntityRelationCollectionResolver;
|
|
55
|
-
function toEntityResponseCollection(items, { args, resourceUID }) {
|
|
55
|
+
async function toEntityResponseCollection(items, { args, resourceUID }) {
|
|
56
56
|
const { toEntityResponseCollection } = strapi.plugin('graphql').service('format').returnTypes;
|
|
57
57
|
return toEntityResponseCollection(items, {
|
|
58
58
|
args,
|
|
59
59
|
resourceUID
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
exports.
|
|
62
|
+
exports.toEntityResponseCollection = toEntityResponseCollection;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type Action = 'create' | 'update' | 'delete' | 'findOne' | 'find';
|
|
2
|
+
interface FieldOperations<T> {
|
|
3
|
+
disable(): this;
|
|
4
|
+
disableInput(): this;
|
|
5
|
+
disableOutput(): this;
|
|
6
|
+
disableFilters(): this;
|
|
7
|
+
isEnabled(): boolean;
|
|
8
|
+
isDisabled(): boolean;
|
|
9
|
+
hasInputEnabled(): boolean;
|
|
10
|
+
hasOutputEnabled(): boolean;
|
|
11
|
+
hasFiltersEnabled(): boolean;
|
|
12
|
+
}
|
|
13
|
+
interface ShadowCRUD<T> {
|
|
14
|
+
disable(): this;
|
|
15
|
+
disableActions(actions: Action[]): this;
|
|
16
|
+
disableAction(action: Action): this;
|
|
17
|
+
disableQueries(): this;
|
|
18
|
+
disableMutations(): this;
|
|
19
|
+
field<K extends keyof T>(name: K): FieldOperations<T[K]>;
|
|
20
|
+
isEnabled(): boolean;
|
|
21
|
+
isDisabled(): boolean;
|
|
22
|
+
areQueriesEnabled(): boolean;
|
|
23
|
+
areQueriesDisabled(): boolean;
|
|
24
|
+
areMutationsEnabled(): boolean;
|
|
25
|
+
areMutationsDisabled(): boolean;
|
|
26
|
+
isActionEnabled(action: Action): boolean;
|
|
27
|
+
isActionDisabled(action: Action): boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare const shadowCRUD: <Type extends unknown = null>(contentTypeUID: string) => ShadowCRUD<Type>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shadowCRUD = void 0;
|
|
4
|
+
const shadowCRUD = (contentTypeUID) => {
|
|
5
|
+
const extensionService = strapi.plugin('graphql').service('extension');
|
|
6
|
+
return extensionService.shadowCRUD(contentTypeUID);
|
|
7
|
+
};
|
|
8
|
+
exports.shadowCRUD = shadowCRUD;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GraphQLResolveInfo } from "graphql";
|
|
2
|
-
type
|
|
2
|
+
export type BaseUser = {
|
|
3
3
|
id: number;
|
|
4
4
|
username: string;
|
|
5
5
|
email: string;
|
|
@@ -20,7 +20,7 @@ type User = {
|
|
|
20
20
|
updatedAt: string;
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
|
-
export type ResolveContext<UserType =
|
|
23
|
+
export type ResolveContext<UserType = BaseUser> = {
|
|
24
24
|
state: {
|
|
25
25
|
route: {
|
|
26
26
|
info: {
|
|
@@ -50,4 +50,3 @@ export type Entity<T extends Object> = {
|
|
|
50
50
|
id: string;
|
|
51
51
|
attributes: Omit<T, 'id'>;
|
|
52
52
|
};
|
|
53
|
-
export {};
|