@strapi/plugin-graphql 4.15.5 → 4.16.0
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/dist/admin/admin/src/index.d.ts +16 -0
- package/dist/admin/admin/src/pluginId.d.ts +1 -0
- package/dist/admin/index.js +31 -17
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +31 -17
- package/dist/admin/index.mjs.map +1 -1
- package/dist/server/bootstrap.d.ts +5 -0
- package/dist/server/bootstrap.d.ts.map +1 -0
- package/dist/server/config/default-config.d.ts +9 -0
- package/dist/server/config/default-config.d.ts.map +1 -0
- package/dist/server/config/index.d.ts +10 -0
- package/dist/server/config/index.d.ts.map +1 -0
- package/dist/server/format-graphql-error.d.ts +4 -0
- package/dist/server/format-graphql-error.d.ts.map +1 -0
- package/dist/server/index.d.ts +301 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +2970 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +2949 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/services/builders/dynamic-zones.d.ts +14 -0
- package/dist/server/services/builders/dynamic-zones.d.ts.map +1 -0
- package/dist/server/services/builders/entity-meta.d.ts +6 -0
- package/dist/server/services/builders/entity-meta.d.ts.map +1 -0
- package/dist/server/services/builders/entity.d.ts +12 -0
- package/dist/server/services/builders/entity.d.ts.map +1 -0
- package/dist/server/services/builders/enums.d.ts +8 -0
- package/dist/server/services/builders/enums.d.ts.map +1 -0
- package/dist/server/services/builders/filters/content-type.d.ts +8 -0
- package/dist/server/services/builders/filters/content-type.d.ts.map +1 -0
- package/dist/server/services/builders/filters/index.d.ts +6 -0
- package/dist/server/services/builders/filters/index.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/and.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/and.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/between.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/between.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/contains.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/contains.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/containsi.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/containsi.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/ends-with.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/ends-with.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/eq.d.ts +11 -0
- package/dist/server/services/builders/filters/operators/eq.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/eqi.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/eqi.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/gt.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/gt.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/gte.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/gte.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/in.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/in.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/index.d.ts +11 -0
- package/dist/server/services/builders/filters/operators/index.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/lt.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/lt.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/lte.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/lte.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/ne.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/ne.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/nei.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/nei.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/not-contains.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/not-contains.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/not-containsi.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/not-containsi.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/not-in.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/not-in.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/not-null.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/not-null.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/not.d.ts +11 -0
- package/dist/server/services/builders/filters/operators/not.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/null.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/null.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/or.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/or.d.ts.map +1 -0
- package/dist/server/services/builders/filters/operators/starts-with.d.ts +8 -0
- package/dist/server/services/builders/filters/operators/starts-with.d.ts.map +1 -0
- package/dist/server/services/builders/generic-morph.d.ts +6 -0
- package/dist/server/services/builders/generic-morph.d.ts.map +1 -0
- package/dist/server/services/builders/index.d.ts +58 -0
- package/dist/server/services/builders/index.d.ts.map +1 -0
- package/dist/server/services/builders/input.d.ts +7 -0
- package/dist/server/services/builders/input.d.ts.map +1 -0
- package/dist/server/services/builders/mutations/collection-type.d.ts +8 -0
- package/dist/server/services/builders/mutations/collection-type.d.ts.map +1 -0
- package/dist/server/services/builders/mutations/index.d.ts +7 -0
- package/dist/server/services/builders/mutations/index.d.ts.map +1 -0
- package/dist/server/services/builders/mutations/single-type.d.ts +8 -0
- package/dist/server/services/builders/mutations/single-type.d.ts.map +1 -0
- package/dist/server/services/builders/queries/collection-type.d.ts +8 -0
- package/dist/server/services/builders/queries/collection-type.d.ts.map +1 -0
- package/dist/server/services/builders/queries/index.d.ts +7 -0
- package/dist/server/services/builders/queries/index.d.ts.map +1 -0
- package/dist/server/services/builders/queries/single-type.d.ts +8 -0
- package/dist/server/services/builders/queries/single-type.d.ts.map +1 -0
- package/dist/server/services/builders/relation-response-collection.d.ts +10 -0
- package/dist/server/services/builders/relation-response-collection.d.ts.map +1 -0
- package/dist/server/services/builders/resolvers/association.d.ts +10 -0
- package/dist/server/services/builders/resolvers/association.d.ts.map +1 -0
- package/dist/server/services/builders/resolvers/component.d.ts +10 -0
- package/dist/server/services/builders/resolvers/component.d.ts.map +1 -0
- package/dist/server/services/builders/resolvers/dynamic-zone.d.ts +10 -0
- package/dist/server/services/builders/resolvers/dynamic-zone.d.ts.map +1 -0
- package/dist/server/services/builders/resolvers/index.d.ts +30 -0
- package/dist/server/services/builders/resolvers/index.d.ts.map +1 -0
- package/dist/server/services/builders/resolvers/mutation.d.ts +13 -0
- package/dist/server/services/builders/resolvers/mutation.d.ts.map +1 -0
- package/dist/server/services/builders/resolvers/query.d.ts +12 -0
- package/dist/server/services/builders/resolvers/query.d.ts.map +1 -0
- package/dist/server/services/builders/response-collection.d.ts +12 -0
- package/dist/server/services/builders/response-collection.d.ts.map +1 -0
- package/dist/server/services/builders/response.d.ts +10 -0
- package/dist/server/services/builders/response.d.ts.map +1 -0
- package/dist/server/services/builders/type.d.ts +19 -0
- package/dist/server/services/builders/type.d.ts.map +1 -0
- package/dist/server/services/builders/utils.d.ts +52 -0
- package/dist/server/services/builders/utils.d.ts.map +1 -0
- package/dist/server/services/constants.d.ts +128 -0
- package/dist/server/services/constants.d.ts.map +1 -0
- package/dist/server/services/content-api/index.d.ts +8 -0
- package/dist/server/services/content-api/index.d.ts.map +1 -0
- package/dist/server/services/content-api/policy.d.ts +7 -0
- package/dist/server/services/content-api/policy.d.ts.map +1 -0
- package/dist/server/services/content-api/register-functions/collection-type.d.ts +9 -0
- package/dist/server/services/content-api/register-functions/collection-type.d.ts.map +1 -0
- package/dist/server/services/content-api/register-functions/component.d.ts +9 -0
- package/dist/server/services/content-api/register-functions/component.d.ts.map +1 -0
- package/dist/server/services/content-api/register-functions/content-type/dynamic-zones.d.ts +9 -0
- package/dist/server/services/content-api/register-functions/content-type/dynamic-zones.d.ts.map +1 -0
- package/dist/server/services/content-api/register-functions/content-type/enums.d.ts +9 -0
- package/dist/server/services/content-api/register-functions/content-type/enums.d.ts.map +1 -0
- package/dist/server/services/content-api/register-functions/content-type/filters.d.ts +9 -0
- package/dist/server/services/content-api/register-functions/content-type/filters.d.ts.map +1 -0
- package/dist/server/services/content-api/register-functions/content-type/index.d.ts +24 -0
- package/dist/server/services/content-api/register-functions/content-type/index.d.ts.map +1 -0
- package/dist/server/services/content-api/register-functions/content-type/inputs.d.ts +9 -0
- package/dist/server/services/content-api/register-functions/content-type/inputs.d.ts.map +1 -0
- package/dist/server/services/content-api/register-functions/index.d.ts +9 -0
- package/dist/server/services/content-api/register-functions/index.d.ts.map +1 -0
- package/dist/server/services/content-api/register-functions/internals.d.ts +4 -0
- package/dist/server/services/content-api/register-functions/internals.d.ts.map +1 -0
- package/dist/server/services/content-api/register-functions/polymorphic.d.ts +5 -0
- package/dist/server/services/content-api/register-functions/polymorphic.d.ts.map +1 -0
- package/dist/server/services/content-api/register-functions/scalars.d.ts +4 -0
- package/dist/server/services/content-api/register-functions/scalars.d.ts.map +1 -0
- package/dist/server/services/content-api/register-functions/single-type.d.ts +9 -0
- package/dist/server/services/content-api/register-functions/single-type.d.ts.map +1 -0
- package/dist/server/services/content-api/wrap-resolvers.d.ts +18 -0
- package/dist/server/services/content-api/wrap-resolvers.d.ts.map +1 -0
- package/dist/server/services/extension/extension.d.ts +63 -0
- package/dist/server/services/extension/extension.d.ts.map +1 -0
- package/dist/server/services/extension/index.d.ts +3 -0
- package/dist/server/services/extension/index.d.ts.map +1 -0
- package/dist/server/services/extension/shadow-crud-manager.d.ts +40 -0
- package/dist/server/services/extension/shadow-crud-manager.d.ts.map +1 -0
- package/dist/server/services/format/index.d.ts +20 -0
- package/dist/server/services/format/index.d.ts.map +1 -0
- package/dist/server/services/format/return-types.d.ts +22 -0
- package/dist/server/services/format/return-types.d.ts.map +1 -0
- package/dist/server/services/index.d.ts +287 -0
- package/dist/server/services/index.d.ts.map +1 -0
- package/dist/server/services/internals/args/index.d.ts +8 -0
- package/dist/server/services/internals/args/index.d.ts.map +1 -0
- package/dist/server/services/internals/args/pagination.d.ts +3 -0
- package/dist/server/services/internals/args/pagination.d.ts.map +1 -0
- package/dist/server/services/internals/args/publication-state.d.ts +4 -0
- package/dist/server/services/internals/args/publication-state.d.ts.map +1 -0
- package/dist/server/services/internals/args/sort.d.ts +3 -0
- package/dist/server/services/internals/args/sort.d.ts.map +1 -0
- package/dist/server/services/internals/helpers/get-enabled-scalars.d.ts +4 -0
- package/dist/server/services/internals/helpers/get-enabled-scalars.d.ts.map +1 -0
- package/dist/server/services/internals/helpers/index.d.ts +6 -0
- package/dist/server/services/internals/helpers/index.d.ts.map +1 -0
- package/dist/server/services/internals/index.d.ts +46 -0
- package/dist/server/services/internals/index.d.ts.map +1 -0
- package/dist/server/services/internals/scalars/date.d.ts +3 -0
- package/dist/server/services/internals/scalars/date.d.ts.map +1 -0
- package/dist/server/services/internals/scalars/index.d.ts +10 -0
- package/dist/server/services/internals/scalars/index.d.ts.map +1 -0
- package/dist/server/services/internals/scalars/time.d.ts +8 -0
- package/dist/server/services/internals/scalars/time.d.ts.map +1 -0
- package/dist/server/services/internals/types/error.d.ts +8 -0
- package/dist/server/services/internals/types/error.d.ts.map +1 -0
- package/dist/server/services/internals/types/filters.d.ts +6 -0
- package/dist/server/services/internals/types/filters.d.ts.map +1 -0
- package/dist/server/services/internals/types/index.d.ts +28 -0
- package/dist/server/services/internals/types/index.d.ts.map +1 -0
- package/dist/server/services/internals/types/pagination.d.ts +10 -0
- package/dist/server/services/internals/types/pagination.d.ts.map +1 -0
- package/dist/server/services/internals/types/publication-state.d.ts +10 -0
- package/dist/server/services/internals/types/publication-state.d.ts.map +1 -0
- package/dist/server/services/internals/types/response-collection-meta.d.ts +11 -0
- package/dist/server/services/internals/types/response-collection-meta.d.ts.map +1 -0
- package/dist/server/services/type-registry.d.ts +15 -0
- package/dist/server/services/type-registry.d.ts.map +1 -0
- package/dist/server/services/types.d.ts +7 -0
- package/dist/server/services/types.d.ts.map +1 -0
- package/dist/server/services/utils/attributes.d.ts +14 -0
- package/dist/server/services/utils/attributes.d.ts.map +1 -0
- package/dist/server/services/utils/index.d.ts +81 -0
- package/dist/server/services/utils/index.d.ts.map +1 -0
- package/dist/server/services/utils/mappers/entity-to-response-entity.d.ts +33 -0
- package/dist/server/services/utils/mappers/entity-to-response-entity.d.ts.map +1 -0
- package/dist/server/services/utils/mappers/graphql-filters-to-strapi-query.d.ts +13 -0
- package/dist/server/services/utils/mappers/graphql-filters-to-strapi-query.d.ts.map +1 -0
- package/dist/server/services/utils/mappers/graphql-scalar-to-operators.d.ts +6 -0
- package/dist/server/services/utils/mappers/graphql-scalar-to-operators.d.ts.map +1 -0
- package/dist/server/services/utils/mappers/index.d.ts +36 -0
- package/dist/server/services/utils/mappers/index.d.ts.map +1 -0
- package/dist/server/services/utils/mappers/strapi-scalar-to-graphql-scalar.d.ts +9 -0
- package/dist/server/services/utils/mappers/strapi-scalar-to-graphql-scalar.d.ts.map +1 -0
- package/dist/server/services/utils/naming.d.ts +37 -0
- package/dist/server/services/utils/naming.d.ts.map +1 -0
- package/package.json +28 -16
- package/strapi-server.js +1 -11
- package/.eslintignore +0 -1
- package/.eslintrc +0 -14
- package/admin/src/index.js +0 -38
- package/admin/src/pluginId.js +0 -5
- package/admin/src/translations/dk.json +0 -5
- package/admin/src/translations/en.json +0 -5
- package/admin/src/translations/es.json +0 -5
- package/admin/src/translations/fr.json +0 -5
- package/admin/src/translations/pl.json +0 -5
- package/admin/src/translations/ru.json +0 -5
- package/admin/src/translations/sv.json +0 -5
- package/admin/src/translations/tr.json +0 -5
- package/admin/src/translations/zh-Hans.json +0 -5
- package/admin/src/translations/zh.json +0 -5
- package/packup.config.ts +0 -42
- package/server/bootstrap.js +0 -134
- package/server/config/default-config.js +0 -13
- package/server/config/index.js +0 -7
- package/server/format-graphql-error.js +0 -45
- package/server/services/builders/dynamic-zones.js +0 -97
- package/server/services/builders/entity-meta.js +0 -7
- package/server/services/builders/entity.js +0 -43
- package/server/services/builders/enums.js +0 -26
- package/server/services/builders/filters/content-type.js +0 -111
- package/server/services/builders/filters/index.js +0 -7
- package/server/services/builders/filters/operators/and.js +0 -15
- package/server/services/builders/filters/operators/between.js +0 -15
- package/server/services/builders/filters/operators/contains.js +0 -13
- package/server/services/builders/filters/operators/containsi.js +0 -13
- package/server/services/builders/filters/operators/ends-with.js +0 -13
- package/server/services/builders/filters/operators/eq.js +0 -23
- package/server/services/builders/filters/operators/eqi.js +0 -13
- package/server/services/builders/filters/operators/gt.js +0 -13
- package/server/services/builders/filters/operators/gte.js +0 -13
- package/server/services/builders/filters/operators/in.js +0 -15
- package/server/services/builders/filters/operators/index.js +0 -40
- package/server/services/builders/filters/operators/lt.js +0 -13
- package/server/services/builders/filters/operators/lte.js +0 -13
- package/server/services/builders/filters/operators/ne.js +0 -13
- package/server/services/builders/filters/operators/nei.js +0 -13
- package/server/services/builders/filters/operators/not-contains.js +0 -13
- package/server/services/builders/filters/operators/not-containsi.js +0 -13
- package/server/services/builders/filters/operators/not-in.js +0 -15
- package/server/services/builders/filters/operators/not-null.js +0 -13
- package/server/services/builders/filters/operators/not.js +0 -19
- package/server/services/builders/filters/operators/null.js +0 -13
- package/server/services/builders/filters/operators/or.js +0 -15
- package/server/services/builders/filters/operators/starts-with.js +0 -13
- package/server/services/builders/generic-morph.js +0 -41
- package/server/services/builders/index.js +0 -92
- package/server/services/builders/input.js +0 -121
- package/server/services/builders/mutations/collection-type.js +0 -191
- package/server/services/builders/mutations/index.js +0 -9
- package/server/services/builders/mutations/single-type.js +0 -164
- package/server/services/builders/queries/collection-type.js +0 -122
- package/server/services/builders/queries/index.js +0 -9
- package/server/services/builders/queries/single-type.js +0 -71
- package/server/services/builders/relation-response-collection.js +0 -32
- package/server/services/builders/resolvers/association.js +0 -92
- package/server/services/builders/resolvers/component.js +0 -25
- package/server/services/builders/resolvers/dynamic-zone.js +0 -9
- package/server/services/builders/resolvers/index.js +0 -18
- package/server/services/builders/resolvers/mutation.js +0 -38
- package/server/services/builders/resolvers/query.js +0 -34
- package/server/services/builders/response-collection.js +0 -40
- package/server/services/builders/response.js +0 -32
- package/server/services/builders/type.js +0 -363
- package/server/services/builders/utils.js +0 -134
- package/server/services/constants.js +0 -153
- package/server/services/content-api/index.js +0 -188
- package/server/services/content-api/policy.js +0 -60
- package/server/services/content-api/register-functions/collection-type.js +0 -72
- package/server/services/content-api/register-functions/component.js +0 -15
- package/server/services/content-api/register-functions/content-type/dynamic-zones.js +0 -36
- package/server/services/content-api/register-functions/content-type/enums.js +0 -33
- package/server/services/content-api/register-functions/content-type/filters.js +0 -15
- package/server/services/content-api/register-functions/content-type/index.js +0 -13
- package/server/services/content-api/register-functions/content-type/inputs.js +0 -21
- package/server/services/content-api/register-functions/index.js +0 -22
- package/server/services/content-api/register-functions/internals.js +0 -13
- package/server/services/content-api/register-functions/polymorphic.js +0 -69
- package/server/services/content-api/register-functions/scalars.js +0 -14
- package/server/services/content-api/register-functions/single-type.js +0 -72
- package/server/services/content-api/wrap-resolvers.js +0 -148
- package/server/services/extension/extension.js +0 -94
- package/server/services/extension/index.js +0 -5
- package/server/services/extension/shadow-crud-manager.js +0 -161
- package/server/services/format/index.js +0 -7
- package/server/services/format/return-types.js +0 -27
- package/server/services/index.js +0 -21
- package/server/services/internals/args/index.js +0 -11
- package/server/services/internals/args/pagination.js +0 -19
- package/server/services/internals/args/publication-state.js +0 -12
- package/server/services/internals/args/sort.js +0 -10
- package/server/services/internals/helpers/get-enabled-scalars.js +0 -17
- package/server/services/internals/helpers/index.js +0 -7
- package/server/services/internals/index.js +0 -13
- package/server/services/internals/scalars/date.js +0 -22
- package/server/services/internals/scalars/index.js +0 -17
- package/server/services/internals/scalars/time.js +0 -36
- package/server/services/internals/types/error.js +0 -34
- package/server/services/internals/types/filters.js +0 -39
- package/server/services/internals/types/index.js +0 -29
- package/server/services/internals/types/pagination.js +0 -24
- package/server/services/internals/types/publication-state.js +0 -24
- package/server/services/internals/types/response-collection-meta.js +0 -46
- package/server/services/type-registry.js +0 -104
- package/server/services/utils/attributes.js +0 -78
- package/server/services/utils/index.js +0 -11
- package/server/services/utils/mappers/entity-to-response-entity.js +0 -12
- package/server/services/utils/mappers/graphql-filters-to-strapi-query.js +0 -119
- package/server/services/utils/mappers/graphql-scalar-to-operators.js +0 -17
- package/server/services/utils/mappers/index.js +0 -13
- package/server/services/utils/mappers/strapi-scalar-to-graphql-scalar.js +0 -25
- package/server/services/utils/naming.js +0 -287
|
@@ -0,0 +1,2949 @@
|
|
|
1
|
+
import { isEmpty, toUpper, snakeCase, pick, mergeWith, isArray, propOr, get, getOr, first, isFunction, isNil, prop, startsWith, difference, propEq, isDate, isObject, has, mapValues, map, upperFirst, camelCase, pipe, lowerFirst, set, omit, identity, constant, isUndefined, isString, defaultTo, entries, reduce, merge as merge$1 } from "lodash/fp";
|
|
2
|
+
import { ForbiddenError as ForbiddenError$2, UserInputError, ApolloError, ApolloServer } from "apollo-server-koa";
|
|
3
|
+
import { ApolloServerPluginLandingPageDisabled, ApolloServerPluginLandingPageGraphQLPlayground } from "apollo-server-core";
|
|
4
|
+
import depthLimit from "graphql-depth-limit";
|
|
5
|
+
import graphqlUploadKoa from "graphql-upload/graphqlUploadKoa.js";
|
|
6
|
+
import { errors, policy, parseType, validate, sanitize, toRegressedEnumValue, contentTypes, pipeAsync, pagination as pagination$1 } from "@strapi/utils";
|
|
7
|
+
import { GraphQLError, GraphQLObjectType, GraphQLScalarType, Kind, valueFromASTUntyped } from "graphql";
|
|
8
|
+
import { pruneSchema } from "@graphql-tools/utils";
|
|
9
|
+
import * as nexus from "nexus";
|
|
10
|
+
import { unionType, makeSchema, arg, list, inputObjectType, asNexusMethod, objectType, enumType, scalarType, nonNull, extendType } from "nexus";
|
|
11
|
+
import { singular } from "pluralize";
|
|
12
|
+
import { GraphQLDate, GraphQLJSON, GraphQLDateTime, GraphQLLong } from "graphql-scalars";
|
|
13
|
+
import GraphQLUpload from "graphql-upload/GraphQLUpload.js";
|
|
14
|
+
const defaultConfig = {
|
|
15
|
+
shadowCRUD: true,
|
|
16
|
+
endpoint: "/graphql",
|
|
17
|
+
subscriptions: false,
|
|
18
|
+
maxLimit: -1,
|
|
19
|
+
apolloServer: {}
|
|
20
|
+
};
|
|
21
|
+
const config = {
|
|
22
|
+
default: defaultConfig
|
|
23
|
+
};
|
|
24
|
+
const { HttpError, ForbiddenError: ForbiddenError$1, UnauthorizedError, ApplicationError: ApplicationError$5, ValidationError: ValidationError$3 } = errors;
|
|
25
|
+
const formatToCode = (name) => `STRAPI_${toUpper(snakeCase(name))}`;
|
|
26
|
+
const formatErrorToExtension = (error2) => ({
|
|
27
|
+
error: pick(["name", "message", "details"])(error2)
|
|
28
|
+
});
|
|
29
|
+
function formatGraphqlError(error2) {
|
|
30
|
+
const { originalError } = error2;
|
|
31
|
+
if (isEmpty(originalError)) {
|
|
32
|
+
return error2;
|
|
33
|
+
}
|
|
34
|
+
if (originalError instanceof ForbiddenError$1 || originalError instanceof UnauthorizedError) {
|
|
35
|
+
return new ForbiddenError$2(originalError.message, formatErrorToExtension(originalError));
|
|
36
|
+
}
|
|
37
|
+
if (originalError instanceof ValidationError$3) {
|
|
38
|
+
return new UserInputError(originalError.message, formatErrorToExtension(originalError));
|
|
39
|
+
}
|
|
40
|
+
if (originalError instanceof ApplicationError$5 || originalError instanceof HttpError) {
|
|
41
|
+
const name = formatToCode(originalError.name);
|
|
42
|
+
return new ApolloError(originalError.message, name, formatErrorToExtension(originalError));
|
|
43
|
+
}
|
|
44
|
+
if (originalError instanceof ApolloError || originalError instanceof GraphQLError) {
|
|
45
|
+
return error2;
|
|
46
|
+
}
|
|
47
|
+
strapi.log.error(originalError);
|
|
48
|
+
return new ApolloError("Internal Server Error", "INTERNAL_SERVER_ERROR");
|
|
49
|
+
}
|
|
50
|
+
const merge = mergeWith((a, b) => {
|
|
51
|
+
if (isArray(a) && isArray(b)) {
|
|
52
|
+
return a.concat(b);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
const useUploadMiddleware = (strapi2, path) => {
|
|
56
|
+
const uploadMiddleware = graphqlUploadKoa();
|
|
57
|
+
strapi2.server.app.use((ctx, next) => {
|
|
58
|
+
if (ctx.path === path) {
|
|
59
|
+
return uploadMiddleware(ctx, next);
|
|
60
|
+
}
|
|
61
|
+
return next();
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
async function bootstrap({ strapi: strapi2 }) {
|
|
65
|
+
const schema = strapi2.plugin("graphql").service("content-api").buildSchema();
|
|
66
|
+
if (isEmpty(schema)) {
|
|
67
|
+
strapi2.log.warn("The GraphQL schema has not been generated because it is empty");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const { config: config2 } = strapi2.plugin("graphql");
|
|
71
|
+
const path = config2("endpoint");
|
|
72
|
+
const defaultServerConfig = {
|
|
73
|
+
// Schema
|
|
74
|
+
schema,
|
|
75
|
+
// Initialize loaders for this request.
|
|
76
|
+
context: ({ ctx }) => ({
|
|
77
|
+
state: ctx.state,
|
|
78
|
+
koaContext: ctx
|
|
79
|
+
}),
|
|
80
|
+
// Validation
|
|
81
|
+
validationRules: [depthLimit(config2("depthLimit"))],
|
|
82
|
+
// Errors
|
|
83
|
+
formatError: formatGraphqlError,
|
|
84
|
+
// Misc
|
|
85
|
+
cors: false,
|
|
86
|
+
uploads: false,
|
|
87
|
+
bodyParserConfig: true,
|
|
88
|
+
plugins: [
|
|
89
|
+
process.env.NODE_ENV === "production" && !config2("playgroundAlways") ? ApolloServerPluginLandingPageDisabled() : ApolloServerPluginLandingPageGraphQLPlayground()
|
|
90
|
+
],
|
|
91
|
+
cache: "bounded"
|
|
92
|
+
};
|
|
93
|
+
const serverConfig = merge(defaultServerConfig, config2("apolloServer"));
|
|
94
|
+
const server = new ApolloServer(serverConfig);
|
|
95
|
+
useUploadMiddleware(strapi2, path);
|
|
96
|
+
try {
|
|
97
|
+
await server.start();
|
|
98
|
+
} catch (error2) {
|
|
99
|
+
if (error2 instanceof Error) {
|
|
100
|
+
strapi2.log.error("Failed to start the Apollo server", error2.message);
|
|
101
|
+
}
|
|
102
|
+
throw error2;
|
|
103
|
+
}
|
|
104
|
+
strapi2.server.routes([
|
|
105
|
+
{
|
|
106
|
+
method: "ALL",
|
|
107
|
+
path,
|
|
108
|
+
handler: [
|
|
109
|
+
(ctx, next) => {
|
|
110
|
+
ctx.state.route = {
|
|
111
|
+
info: {
|
|
112
|
+
// Indicate it's a content API route
|
|
113
|
+
type: "content-api"
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
if (ctx.request.method === "GET")
|
|
117
|
+
return next();
|
|
118
|
+
return strapi2.auth.authenticate(ctx, next);
|
|
119
|
+
},
|
|
120
|
+
// Apollo Server
|
|
121
|
+
server.getMiddleware({
|
|
122
|
+
path,
|
|
123
|
+
cors: serverConfig.cors,
|
|
124
|
+
bodyParserConfig: serverConfig.bodyParserConfig
|
|
125
|
+
})
|
|
126
|
+
],
|
|
127
|
+
config: {
|
|
128
|
+
auth: false
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
]);
|
|
132
|
+
strapi2.plugin("graphql").destroy = async () => {
|
|
133
|
+
await server.stop();
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const { PolicyError } = errors;
|
|
137
|
+
const getPoliciesConfig = propOr([], "policies");
|
|
138
|
+
const createPoliciesMiddleware = (resolverConfig, { strapi: strapi2 }) => {
|
|
139
|
+
const resolverPolicies = getPoliciesConfig(resolverConfig);
|
|
140
|
+
const policies = policy.resolve(resolverPolicies, {});
|
|
141
|
+
return async (resolve, parent, args2, context, info) => {
|
|
142
|
+
const policyContext = createGraphQLPolicyContext(parent, args2, context, info);
|
|
143
|
+
for (const { handler, config: config2 } of policies) {
|
|
144
|
+
const result = await handler(policyContext, config2, { strapi: strapi2 });
|
|
145
|
+
if (![true, void 0].includes(result)) {
|
|
146
|
+
throw new PolicyError();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return resolve(parent, args2, context, info);
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const createGraphQLPolicyContext = (parent, args2, context, info) => {
|
|
153
|
+
const policyContext = {
|
|
154
|
+
get parent() {
|
|
155
|
+
return parent;
|
|
156
|
+
},
|
|
157
|
+
get args() {
|
|
158
|
+
return args2;
|
|
159
|
+
},
|
|
160
|
+
get context() {
|
|
161
|
+
return context;
|
|
162
|
+
},
|
|
163
|
+
get info() {
|
|
164
|
+
return info;
|
|
165
|
+
},
|
|
166
|
+
get state() {
|
|
167
|
+
return this.context.state;
|
|
168
|
+
},
|
|
169
|
+
get http() {
|
|
170
|
+
return this.context.koaContext;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
return policy.createPolicyContext("graphql", policyContext);
|
|
174
|
+
};
|
|
175
|
+
const { ForbiddenError } = errors;
|
|
176
|
+
const introspectionQueries = [
|
|
177
|
+
"__Schema",
|
|
178
|
+
"__Type",
|
|
179
|
+
"__Field",
|
|
180
|
+
"__InputValue",
|
|
181
|
+
"__EnumValue",
|
|
182
|
+
"__Directive"
|
|
183
|
+
];
|
|
184
|
+
const parseMiddlewares = (resolverConfig, strapi2) => {
|
|
185
|
+
const resolverMiddlewares = getOr([], "middlewares", resolverConfig);
|
|
186
|
+
return resolverMiddlewares.map(
|
|
187
|
+
(middleware) => {
|
|
188
|
+
if (isFunction(middleware)) {
|
|
189
|
+
return middleware;
|
|
190
|
+
}
|
|
191
|
+
if (typeof middleware === "string") {
|
|
192
|
+
return strapi2.middleware(middleware);
|
|
193
|
+
}
|
|
194
|
+
if (typeof middleware === "object") {
|
|
195
|
+
const { name, options = {} } = middleware;
|
|
196
|
+
return strapi2.middleware(name)(options, { strapi: strapi2 });
|
|
197
|
+
}
|
|
198
|
+
throw new Error(
|
|
199
|
+
`Invalid middleware type, expected (function,string,object), received ${typeof middleware}`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
const wrapResolvers = ({
|
|
205
|
+
schema,
|
|
206
|
+
strapi: strapi2,
|
|
207
|
+
extension = {}
|
|
208
|
+
}) => {
|
|
209
|
+
const { resolversConfig = {} } = extension;
|
|
210
|
+
const isValidFieldName = (field) => !field.startsWith("__");
|
|
211
|
+
const typeMap = schema.getTypeMap();
|
|
212
|
+
Object.entries(typeMap).forEach(([type, definition]) => {
|
|
213
|
+
const isGraphQLObjectType = definition instanceof GraphQLObjectType;
|
|
214
|
+
const isIgnoredType = introspectionQueries.includes(type);
|
|
215
|
+
if (!isGraphQLObjectType || isIgnoredType) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const fields = definition.getFields();
|
|
219
|
+
const fieldsToProcess = Object.entries(fields).filter(([field]) => isValidFieldName(field));
|
|
220
|
+
for (const [fieldName, fieldDefinition] of fieldsToProcess) {
|
|
221
|
+
const defaultResolver = get(fieldName);
|
|
222
|
+
const path = `${type}.${fieldName}`;
|
|
223
|
+
const resolverConfig = getOr({}, path, resolversConfig);
|
|
224
|
+
const { resolve: baseResolver = defaultResolver } = fieldDefinition;
|
|
225
|
+
const middlewares = parseMiddlewares(resolverConfig, strapi2);
|
|
226
|
+
const policyMiddleware = createPoliciesMiddleware(resolverConfig, { strapi: strapi2 });
|
|
227
|
+
middlewares.push(policyMiddleware);
|
|
228
|
+
const boundMiddlewares = middlewares.map((middleware, index2, collection) => {
|
|
229
|
+
return (parents, args2, context, info) => middleware(
|
|
230
|
+
// Make sure the last middleware in the list calls the baseResolver
|
|
231
|
+
index2 >= collection.length - 1 ? baseResolver : boundMiddlewares[index2 + 1],
|
|
232
|
+
parents,
|
|
233
|
+
args2,
|
|
234
|
+
context,
|
|
235
|
+
info
|
|
236
|
+
);
|
|
237
|
+
});
|
|
238
|
+
const authorize = async ({ context }) => {
|
|
239
|
+
const authConfig = get("auth", resolverConfig);
|
|
240
|
+
const authContext = get("state.auth", context);
|
|
241
|
+
const isValidType = ["Mutation", "Query", "Subscription"].includes(type);
|
|
242
|
+
const hasConfig = !isNil(authConfig);
|
|
243
|
+
const isAuthDisabled = authConfig === false;
|
|
244
|
+
if ((isValidType || hasConfig) && !isAuthDisabled) {
|
|
245
|
+
try {
|
|
246
|
+
await strapi2.auth.verify(authContext, authConfig);
|
|
247
|
+
} catch (error2) {
|
|
248
|
+
throw new ForbiddenError();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
fieldDefinition.resolve = async (parent, args2, context, info) => {
|
|
253
|
+
await authorize({ context });
|
|
254
|
+
return first(boundMiddlewares)(parent, args2, context, info);
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
return schema;
|
|
259
|
+
};
|
|
260
|
+
const registerCollectionType = (contentType2, {
|
|
261
|
+
registry,
|
|
262
|
+
strapi: strapi2,
|
|
263
|
+
builders: builders2
|
|
264
|
+
}) => {
|
|
265
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
266
|
+
const { naming: naming2 } = getService("utils");
|
|
267
|
+
const { KINDS: KINDS2 } = getService("constants");
|
|
268
|
+
const extension = getService("extension");
|
|
269
|
+
const types2 = {
|
|
270
|
+
base: naming2.getTypeName(contentType2),
|
|
271
|
+
entity: naming2.getEntityName(contentType2),
|
|
272
|
+
response: naming2.getEntityResponseName(contentType2),
|
|
273
|
+
responseCollection: naming2.getEntityResponseCollectionName(contentType2),
|
|
274
|
+
relationResponseCollection: naming2.getRelationResponseCollectionName(contentType2),
|
|
275
|
+
queries: naming2.getEntityQueriesTypeName(contentType2),
|
|
276
|
+
mutations: naming2.getEntityMutationsTypeName(contentType2)
|
|
277
|
+
};
|
|
278
|
+
const getConfig = (kind) => ({ kind, contentType: contentType2 });
|
|
279
|
+
registry.register(types2.base, builders2.buildTypeDefinition(contentType2), getConfig(KINDS2.type));
|
|
280
|
+
registry.register(
|
|
281
|
+
types2.entity,
|
|
282
|
+
builders2.buildEntityDefinition(contentType2),
|
|
283
|
+
getConfig(KINDS2.entity)
|
|
284
|
+
);
|
|
285
|
+
registry.register(
|
|
286
|
+
types2.response,
|
|
287
|
+
builders2.buildResponseDefinition(contentType2),
|
|
288
|
+
getConfig(KINDS2.entityResponse)
|
|
289
|
+
);
|
|
290
|
+
registry.register(
|
|
291
|
+
types2.responseCollection,
|
|
292
|
+
builders2.buildResponseCollectionDefinition(contentType2),
|
|
293
|
+
getConfig(KINDS2.entityResponseCollection)
|
|
294
|
+
);
|
|
295
|
+
registry.register(
|
|
296
|
+
types2.relationResponseCollection,
|
|
297
|
+
builders2.buildRelationResponseCollectionDefinition(contentType2),
|
|
298
|
+
getConfig(KINDS2.relationResponseCollection)
|
|
299
|
+
);
|
|
300
|
+
if (extension.shadowCRUD(contentType2.uid).areQueriesEnabled()) {
|
|
301
|
+
registry.register(
|
|
302
|
+
types2.queries,
|
|
303
|
+
builders2.buildCollectionTypeQueries(contentType2),
|
|
304
|
+
getConfig(KINDS2.query)
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
if (extension.shadowCRUD(contentType2.uid).areMutationsEnabled()) {
|
|
308
|
+
registry.register(
|
|
309
|
+
types2.mutations,
|
|
310
|
+
builders2.buildCollectionTypeMutations(contentType2),
|
|
311
|
+
getConfig(KINDS2.mutation)
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
const registerSingleType = (contentType2, {
|
|
316
|
+
registry,
|
|
317
|
+
strapi: strapi2,
|
|
318
|
+
builders: builders2
|
|
319
|
+
}) => {
|
|
320
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
321
|
+
const { naming: naming2 } = getService("utils");
|
|
322
|
+
const { KINDS: KINDS2 } = getService("constants");
|
|
323
|
+
const extension = getService("extension");
|
|
324
|
+
const types2 = {
|
|
325
|
+
base: naming2.getTypeName(contentType2),
|
|
326
|
+
entity: naming2.getEntityName(contentType2),
|
|
327
|
+
response: naming2.getEntityResponseName(contentType2),
|
|
328
|
+
responseCollection: naming2.getEntityResponseCollectionName(contentType2),
|
|
329
|
+
relationResponseCollection: naming2.getRelationResponseCollectionName(contentType2),
|
|
330
|
+
queries: naming2.getEntityQueriesTypeName(contentType2),
|
|
331
|
+
mutations: naming2.getEntityMutationsTypeName(contentType2)
|
|
332
|
+
};
|
|
333
|
+
const getConfig = (kind) => ({ kind, contentType: contentType2 });
|
|
334
|
+
registry.register(types2.base, builders2.buildTypeDefinition(contentType2), getConfig(KINDS2.type));
|
|
335
|
+
registry.register(
|
|
336
|
+
types2.entity,
|
|
337
|
+
builders2.buildEntityDefinition(contentType2),
|
|
338
|
+
getConfig(KINDS2.entity)
|
|
339
|
+
);
|
|
340
|
+
registry.register(
|
|
341
|
+
types2.response,
|
|
342
|
+
builders2.buildResponseDefinition(contentType2),
|
|
343
|
+
getConfig(KINDS2.entityResponse)
|
|
344
|
+
);
|
|
345
|
+
registry.register(
|
|
346
|
+
types2.responseCollection,
|
|
347
|
+
builders2.buildResponseCollectionDefinition(contentType2),
|
|
348
|
+
getConfig(KINDS2.entityResponseCollection)
|
|
349
|
+
);
|
|
350
|
+
registry.register(
|
|
351
|
+
types2.relationResponseCollection,
|
|
352
|
+
builders2.buildRelationResponseCollectionDefinition(contentType2),
|
|
353
|
+
getConfig(KINDS2.relationResponseCollection)
|
|
354
|
+
);
|
|
355
|
+
if (extension.shadowCRUD(contentType2.uid).areQueriesEnabled()) {
|
|
356
|
+
registry.register(
|
|
357
|
+
types2.queries,
|
|
358
|
+
builders2.buildSingleTypeQueries(contentType2),
|
|
359
|
+
getConfig(KINDS2.query)
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
if (extension.shadowCRUD(contentType2.uid).areMutationsEnabled()) {
|
|
363
|
+
registry.register(
|
|
364
|
+
types2.mutations,
|
|
365
|
+
builders2.buildSingleTypeMutations(contentType2),
|
|
366
|
+
getConfig(KINDS2.mutation)
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
const registerComponent = (contentType2, {
|
|
371
|
+
registry,
|
|
372
|
+
strapi: strapi2,
|
|
373
|
+
builders: builders2
|
|
374
|
+
}) => {
|
|
375
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
376
|
+
const { getComponentName } = getService("utils").naming;
|
|
377
|
+
const { KINDS: KINDS2 } = getService("constants");
|
|
378
|
+
const name = getComponentName(contentType2);
|
|
379
|
+
const definition = builders2.buildTypeDefinition(contentType2);
|
|
380
|
+
registry.register(name, definition, { kind: KINDS2.component, contentType: contentType2 });
|
|
381
|
+
};
|
|
382
|
+
const registerPolymorphicContentType = (contentType2, { registry, strapi: strapi2 }) => {
|
|
383
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
384
|
+
const {
|
|
385
|
+
naming: naming2,
|
|
386
|
+
attributes: { isMorphRelation }
|
|
387
|
+
} = getService("utils");
|
|
388
|
+
const { KINDS: KINDS2 } = getService("constants");
|
|
389
|
+
const { attributes: attributes2 = {} } = contentType2;
|
|
390
|
+
const morphAttributes = Object.entries(attributes2).filter(
|
|
391
|
+
([, attribute]) => isMorphRelation(attribute)
|
|
392
|
+
);
|
|
393
|
+
for (const [attributeName, attribute] of morphAttributes) {
|
|
394
|
+
const name = naming2.getMorphRelationTypeName(contentType2, attributeName);
|
|
395
|
+
const { target } = attribute;
|
|
396
|
+
if (!Array.isArray(target)) {
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
const members = target.map((uid) => strapi2.getModel(uid)).map((contentType22) => naming2.getTypeName(contentType22));
|
|
400
|
+
registry.register(
|
|
401
|
+
name,
|
|
402
|
+
unionType({
|
|
403
|
+
name,
|
|
404
|
+
resolveType(obj) {
|
|
405
|
+
const contentType22 = strapi2.getModel(obj.__type);
|
|
406
|
+
if (!contentType22) {
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
if (contentType22.modelType === "component") {
|
|
410
|
+
return naming2.getComponentName(contentType22);
|
|
411
|
+
}
|
|
412
|
+
return naming2.getTypeName(contentType22);
|
|
413
|
+
},
|
|
414
|
+
definition(t) {
|
|
415
|
+
t.members(...members);
|
|
416
|
+
}
|
|
417
|
+
}),
|
|
418
|
+
{ kind: KINDS2.morph, contentType: contentType2, attributeName }
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
const registerScalars = ({ registry, strapi: strapi2 }) => {
|
|
423
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
424
|
+
const { scalars: scalars2 } = getService("internals");
|
|
425
|
+
const { KINDS: KINDS2 } = getService("constants");
|
|
426
|
+
Object.entries(scalars2).forEach(([name, definition]) => {
|
|
427
|
+
registry.register(name, definition, { kind: KINDS2.scalar });
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
const registerInternals = ({ registry, strapi: strapi2 }) => {
|
|
431
|
+
const { buildInternalTypes } = strapi2.plugin("graphql").service("internals");
|
|
432
|
+
const internalTypes = buildInternalTypes({ strapi: strapi2 });
|
|
433
|
+
for (const [kind, definitions] of Object.entries(internalTypes)) {
|
|
434
|
+
registry.registerMany(Object.entries(definitions), { kind });
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
const registerDynamicZonesDefinition$1 = (contentType2, {
|
|
438
|
+
registry,
|
|
439
|
+
strapi: strapi2,
|
|
440
|
+
builders: builders2
|
|
441
|
+
}) => {
|
|
442
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
443
|
+
const {
|
|
444
|
+
naming: naming2,
|
|
445
|
+
attributes: { isDynamicZone }
|
|
446
|
+
} = getService("utils");
|
|
447
|
+
const { KINDS: KINDS2 } = getService("constants");
|
|
448
|
+
const { attributes: attributes2 } = contentType2;
|
|
449
|
+
const dynamicZoneAttributes = Object.keys(attributes2).filter(
|
|
450
|
+
(attributeName) => isDynamicZone(attributes2[attributeName])
|
|
451
|
+
);
|
|
452
|
+
for (const attributeName of dynamicZoneAttributes) {
|
|
453
|
+
const attribute = attributes2[attributeName];
|
|
454
|
+
const dzName = naming2.getDynamicZoneName(contentType2, attributeName);
|
|
455
|
+
const dzInputName = naming2.getDynamicZoneInputName(contentType2, attributeName);
|
|
456
|
+
const [type, input] = builders2.buildDynamicZoneDefinition(attribute, dzName, dzInputName);
|
|
457
|
+
const baseConfig = {
|
|
458
|
+
contentType: contentType2,
|
|
459
|
+
attributeName,
|
|
460
|
+
attribute
|
|
461
|
+
};
|
|
462
|
+
registry.register(dzName, type, { kind: KINDS2.dynamicZone, ...baseConfig });
|
|
463
|
+
registry.register(dzInputName, input, { kind: KINDS2.input, ...baseConfig });
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
const registerEnumsDefinition$1 = (contentType2, {
|
|
467
|
+
registry,
|
|
468
|
+
strapi: strapi2,
|
|
469
|
+
builders: builders2
|
|
470
|
+
}) => {
|
|
471
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
472
|
+
const {
|
|
473
|
+
naming: naming2,
|
|
474
|
+
attributes: { isEnumeration }
|
|
475
|
+
} = getService("utils");
|
|
476
|
+
const { KINDS: KINDS2 } = getService("constants");
|
|
477
|
+
const { attributes: attributes2 } = contentType2;
|
|
478
|
+
const enumAttributes = Object.keys(attributes2).filter(
|
|
479
|
+
(attributeName) => isEnumeration(attributes2[attributeName])
|
|
480
|
+
);
|
|
481
|
+
for (const attributeName of enumAttributes) {
|
|
482
|
+
const attribute = attributes2[attributeName];
|
|
483
|
+
const enumName = naming2.getEnumName(contentType2, attributeName);
|
|
484
|
+
const enumDefinition = builders2.buildEnumTypeDefinition(attribute, enumName);
|
|
485
|
+
registry.register(enumName, enumDefinition, {
|
|
486
|
+
kind: KINDS2.enum,
|
|
487
|
+
contentType: contentType2,
|
|
488
|
+
attributeName,
|
|
489
|
+
attribute
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
const registerInputsDefinition$1 = (contentType2, {
|
|
494
|
+
registry,
|
|
495
|
+
strapi: strapi2,
|
|
496
|
+
builders: builders2
|
|
497
|
+
}) => {
|
|
498
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
499
|
+
const { getComponentInputName, getContentTypeInputName } = getService("utils").naming;
|
|
500
|
+
const { KINDS: KINDS2 } = getService("constants");
|
|
501
|
+
const { modelType } = contentType2;
|
|
502
|
+
const type = (modelType === "component" ? getComponentInputName : getContentTypeInputName).call(
|
|
503
|
+
null,
|
|
504
|
+
contentType2
|
|
505
|
+
);
|
|
506
|
+
const definition = builders2.buildInputType(contentType2);
|
|
507
|
+
registry.register(type, definition, { kind: KINDS2.input, contentType: contentType2 });
|
|
508
|
+
};
|
|
509
|
+
const registerFiltersDefinition$1 = (contentType2, {
|
|
510
|
+
registry,
|
|
511
|
+
strapi: strapi2,
|
|
512
|
+
builders: builders2
|
|
513
|
+
}) => {
|
|
514
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
515
|
+
const { getFiltersInputTypeName } = getService("utils").naming;
|
|
516
|
+
const { KINDS: KINDS2 } = getService("constants");
|
|
517
|
+
const type = getFiltersInputTypeName(contentType2);
|
|
518
|
+
const definition = builders2.buildContentTypeFilters(contentType2);
|
|
519
|
+
registry.register(type, definition, { kind: KINDS2.filtersInput, contentType: contentType2 });
|
|
520
|
+
};
|
|
521
|
+
const contentType$1 = {
|
|
522
|
+
registerDynamicZonesDefinition: registerDynamicZonesDefinition$1,
|
|
523
|
+
registerFiltersDefinition: registerFiltersDefinition$1,
|
|
524
|
+
registerInputsDefinition: registerInputsDefinition$1,
|
|
525
|
+
registerEnumsDefinition: registerEnumsDefinition$1
|
|
526
|
+
};
|
|
527
|
+
const {
|
|
528
|
+
registerEnumsDefinition,
|
|
529
|
+
registerInputsDefinition,
|
|
530
|
+
registerFiltersDefinition,
|
|
531
|
+
registerDynamicZonesDefinition
|
|
532
|
+
} = contentType$1;
|
|
533
|
+
const contentAPI = ({ strapi: strapi2 }) => {
|
|
534
|
+
const { mergeSchemas, addResolversToSchema } = require("@graphql-tools/schema");
|
|
535
|
+
const { service: getGraphQLService } = strapi2.plugin("graphql");
|
|
536
|
+
const { config: config2 } = strapi2.plugin("graphql");
|
|
537
|
+
const { KINDS: KINDS2, GENERIC_MORPH_TYPENAME: GENERIC_MORPH_TYPENAME2 } = getGraphQLService("constants");
|
|
538
|
+
const extensionService = getGraphQLService("extension");
|
|
539
|
+
let registry;
|
|
540
|
+
let builders2;
|
|
541
|
+
const buildSchema = () => {
|
|
542
|
+
const isShadowCRUDEnabled = !!config2("shadowCRUD");
|
|
543
|
+
registry = getGraphQLService("type-registry").new();
|
|
544
|
+
builders2 = getGraphQLService("builders").new("content-api", registry);
|
|
545
|
+
registerScalars({ registry, strapi: strapi2 });
|
|
546
|
+
registerInternals({ registry, strapi: strapi2 });
|
|
547
|
+
if (isShadowCRUDEnabled) {
|
|
548
|
+
shadowCRUD();
|
|
549
|
+
}
|
|
550
|
+
const schema = buildMergedSchema({ registry });
|
|
551
|
+
const extension = extensionService.generate({ typeRegistry: registry });
|
|
552
|
+
const schemaWithResolvers = addResolversToSchema(schema, extension.resolvers);
|
|
553
|
+
const outputs = {
|
|
554
|
+
schema: config2("artifacts.schema", false),
|
|
555
|
+
typegen: config2("artifacts.typegen", false)
|
|
556
|
+
};
|
|
557
|
+
const currentEnv = strapi2.config.get("environment");
|
|
558
|
+
const nexusSchema = makeSchema({
|
|
559
|
+
types: [],
|
|
560
|
+
// Build the schema from the merged GraphQL schema.
|
|
561
|
+
// Since we're passing the schema to the mergeSchema property, it'll transform our SDL type definitions
|
|
562
|
+
// into Nexus type definition, thus allowing them to be handled by Nexus plugins & other processing
|
|
563
|
+
mergeSchema: { schema: schemaWithResolvers },
|
|
564
|
+
// Apply user-defined plugins
|
|
565
|
+
plugins: extension.plugins,
|
|
566
|
+
// Whether to generate artifacts (GraphQL schema, TS types definitions) or not.
|
|
567
|
+
// By default, we generate artifacts only on development environment
|
|
568
|
+
shouldGenerateArtifacts: config2("generateArtifacts", currentEnv === "development"),
|
|
569
|
+
// Artifacts generation configuration
|
|
570
|
+
outputs
|
|
571
|
+
});
|
|
572
|
+
const wrappedNexusSchema = wrapResolvers({ schema: nexusSchema, strapi: strapi2, extension });
|
|
573
|
+
const prunedNexusSchema = pruneSchema(wrappedNexusSchema);
|
|
574
|
+
return prunedNexusSchema;
|
|
575
|
+
};
|
|
576
|
+
const buildMergedSchema = ({ registry: registry2 }) => {
|
|
577
|
+
const { types: types2, typeDefs = [] } = extensionService.generate({ typeRegistry: registry2 });
|
|
578
|
+
const nexusSchema = makeSchema({ types: [registry2.definitions, types2] });
|
|
579
|
+
return mergeSchemas({
|
|
580
|
+
typeDefs,
|
|
581
|
+
// Give access to the shadowCRUD & nexus based types
|
|
582
|
+
// Note: This is necessary so that types defined in SDL can reference types defined with Nexus
|
|
583
|
+
schemas: [nexusSchema]
|
|
584
|
+
});
|
|
585
|
+
};
|
|
586
|
+
const shadowCRUD = () => {
|
|
587
|
+
const extensionService2 = getGraphQLService("extension");
|
|
588
|
+
const contentTypes2 = [
|
|
589
|
+
...Object.values(strapi2.components),
|
|
590
|
+
...Object.values(strapi2.contentTypes)
|
|
591
|
+
];
|
|
592
|
+
contentTypes2.map(prop("uid")).filter(startsWith("admin::")).forEach((uid) => extensionService2.shadowCRUD(uid).disable());
|
|
593
|
+
const contentTypesWithShadowCRUD = contentTypes2.filter(
|
|
594
|
+
(ct) => extensionService2.shadowCRUD(ct.uid).isEnabled()
|
|
595
|
+
);
|
|
596
|
+
registerAPITypes(contentTypesWithShadowCRUD);
|
|
597
|
+
registerMorphTypes(contentTypesWithShadowCRUD);
|
|
598
|
+
};
|
|
599
|
+
const registerAPITypes = (contentTypes2) => {
|
|
600
|
+
for (const contentType2 of contentTypes2) {
|
|
601
|
+
const { modelType } = contentType2;
|
|
602
|
+
const registerOptions = { registry, strapi: strapi2, builders: builders2 };
|
|
603
|
+
registerEnumsDefinition(contentType2, registerOptions);
|
|
604
|
+
registerDynamicZonesDefinition(contentType2, registerOptions);
|
|
605
|
+
registerFiltersDefinition(contentType2, registerOptions);
|
|
606
|
+
registerInputsDefinition(contentType2, registerOptions);
|
|
607
|
+
if (modelType === "component") {
|
|
608
|
+
registerComponent(contentType2, registerOptions);
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
const { kind } = contentType2;
|
|
612
|
+
if (kind === "singleType") {
|
|
613
|
+
registerSingleType(contentType2, registerOptions);
|
|
614
|
+
} else if (kind === "collectionType") {
|
|
615
|
+
registerCollectionType(contentType2, registerOptions);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
const registerMorphTypes = (contentTypes2) => {
|
|
620
|
+
const genericMorphType = builders2.buildGenericMorphDefinition();
|
|
621
|
+
registry.register(GENERIC_MORPH_TYPENAME2, genericMorphType, { kind: KINDS2.morph });
|
|
622
|
+
for (const contentType2 of contentTypes2) {
|
|
623
|
+
registerPolymorphicContentType(contentType2, { registry, strapi: strapi2 });
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
return { buildSchema };
|
|
627
|
+
};
|
|
628
|
+
const { ApplicationError: ApplicationError$4 } = errors;
|
|
629
|
+
const createTypeRegistry = () => {
|
|
630
|
+
const registry = /* @__PURE__ */ new Map();
|
|
631
|
+
const typeRegistry2 = {
|
|
632
|
+
/**
|
|
633
|
+
* Register a new type definition
|
|
634
|
+
*/
|
|
635
|
+
register(name, definition, config2 = {}) {
|
|
636
|
+
if (registry.has(name)) {
|
|
637
|
+
throw new ApplicationError$4(`"${name}" has already been registered`);
|
|
638
|
+
}
|
|
639
|
+
registry.set(name, { name, definition, config: config2 });
|
|
640
|
+
return this;
|
|
641
|
+
},
|
|
642
|
+
/**
|
|
643
|
+
* Register many types definitions at once
|
|
644
|
+
* @param {[string, NexusAcceptedTypeDef][]} definitionsEntries
|
|
645
|
+
* @param {object | function} [config]
|
|
646
|
+
*/
|
|
647
|
+
registerMany(definitionsEntries, config2 = {}) {
|
|
648
|
+
for (const [name, definition] of definitionsEntries) {
|
|
649
|
+
this.register(name, definition, isFunction(config2) ? config2(name, definition) : config2);
|
|
650
|
+
}
|
|
651
|
+
return this;
|
|
652
|
+
},
|
|
653
|
+
/**
|
|
654
|
+
* Check if the given type name has already been added to the registry
|
|
655
|
+
* @param {string} name
|
|
656
|
+
* @return {boolean}
|
|
657
|
+
*/
|
|
658
|
+
has(name) {
|
|
659
|
+
return registry.has(name);
|
|
660
|
+
},
|
|
661
|
+
/**
|
|
662
|
+
* Get the type definition for `name`
|
|
663
|
+
* @param {string} name - The name of the type
|
|
664
|
+
*/
|
|
665
|
+
get(name) {
|
|
666
|
+
return registry.get(name);
|
|
667
|
+
},
|
|
668
|
+
/**
|
|
669
|
+
* Transform and return the registry as an object
|
|
670
|
+
* @return {Object<string, RegisteredTypeDef>}
|
|
671
|
+
*/
|
|
672
|
+
toObject() {
|
|
673
|
+
return Object.fromEntries(registry.entries());
|
|
674
|
+
},
|
|
675
|
+
/**
|
|
676
|
+
* Return the name of every registered type
|
|
677
|
+
* @return {string[]}
|
|
678
|
+
*/
|
|
679
|
+
get types() {
|
|
680
|
+
return Array.from(registry.keys());
|
|
681
|
+
},
|
|
682
|
+
/**
|
|
683
|
+
* Return all the registered definitions as an array
|
|
684
|
+
* @return {RegisteredTypeDef[]}
|
|
685
|
+
*/
|
|
686
|
+
get definitions() {
|
|
687
|
+
return Array.from(registry.values());
|
|
688
|
+
},
|
|
689
|
+
/**
|
|
690
|
+
* Filter and return the types definitions that matches the given predicate
|
|
691
|
+
* @param {function(RegisteredTypeDef): boolean} predicate
|
|
692
|
+
* @return {RegisteredTypeDef[]}
|
|
693
|
+
*/
|
|
694
|
+
where(predicate) {
|
|
695
|
+
return this.definitions.filter(predicate);
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
return typeRegistry2;
|
|
699
|
+
};
|
|
700
|
+
const typeRegistry = () => ({
|
|
701
|
+
new: createTypeRegistry
|
|
702
|
+
});
|
|
703
|
+
const { ApplicationError: ApplicationError$3 } = errors;
|
|
704
|
+
const strapiScalarToGraphQLScalar = ({ strapi: strapi2 }) => {
|
|
705
|
+
const { STRAPI_SCALARS: STRAPI_SCALARS2, SCALARS_ASSOCIATIONS: SCALARS_ASSOCIATIONS2 } = strapi2.plugin("graphql").service("constants");
|
|
706
|
+
const missingStrapiScalars = difference(STRAPI_SCALARS2, Object.keys(SCALARS_ASSOCIATIONS2));
|
|
707
|
+
if (missingStrapiScalars.length > 0) {
|
|
708
|
+
throw new ApplicationError$3("Some Strapi scalars are not handled in the GraphQL scalars mapper");
|
|
709
|
+
}
|
|
710
|
+
return {
|
|
711
|
+
/**
|
|
712
|
+
* Used to transform a Strapi scalar type into its GraphQL equivalent
|
|
713
|
+
*/
|
|
714
|
+
strapiScalarToGraphQLScalar(strapiScalar) {
|
|
715
|
+
return get(strapiScalar, SCALARS_ASSOCIATIONS2);
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
};
|
|
719
|
+
const virtualScalarAttributes = ["id"];
|
|
720
|
+
const graphQLFiltersToStrapiQuery = ({ strapi: strapi2 }) => {
|
|
721
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
722
|
+
const recursivelyReplaceScalarOperators = (data) => {
|
|
723
|
+
const { operators: operators2 } = getService("builders").filters;
|
|
724
|
+
if (Array.isArray(data)) {
|
|
725
|
+
return data.map(recursivelyReplaceScalarOperators);
|
|
726
|
+
}
|
|
727
|
+
if (isDate(data) || !isObject(data)) {
|
|
728
|
+
return data;
|
|
729
|
+
}
|
|
730
|
+
const result = {};
|
|
731
|
+
for (const [key, value] of Object.entries(data)) {
|
|
732
|
+
const isOperator = !!operators2[key];
|
|
733
|
+
const newKey = isOperator ? operators2[key].strapiOperator : key;
|
|
734
|
+
result[newKey] = recursivelyReplaceScalarOperators(value);
|
|
735
|
+
}
|
|
736
|
+
return result;
|
|
737
|
+
};
|
|
738
|
+
return {
|
|
739
|
+
/**
|
|
740
|
+
* Transform one or many GraphQL filters object into a valid Strapi query
|
|
741
|
+
* @param {object | object[]} filters
|
|
742
|
+
* @param {object} contentType
|
|
743
|
+
* @return {object | object[]}
|
|
744
|
+
*/
|
|
745
|
+
graphQLFiltersToStrapiQuery(filters2, contentType2) {
|
|
746
|
+
const { isStrapiScalar, isMedia, isRelation, isComponent } = getService("utils").attributes;
|
|
747
|
+
const { operators: operators2 } = getService("builders").filters;
|
|
748
|
+
const ROOT_LEVEL_OPERATORS = [operators2.and, operators2.or, operators2.not];
|
|
749
|
+
if (isNil(filters2)) {
|
|
750
|
+
return {};
|
|
751
|
+
}
|
|
752
|
+
if (Array.isArray(filters2)) {
|
|
753
|
+
return filters2.map(
|
|
754
|
+
(filtersItem) => this.graphQLFiltersToStrapiQuery(filtersItem, contentType2)
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
const resultMap = {};
|
|
758
|
+
const { attributes: attributes2 } = contentType2;
|
|
759
|
+
const isAttribute = (attributeName) => {
|
|
760
|
+
return virtualScalarAttributes.includes(attributeName) || has(attributeName, attributes2);
|
|
761
|
+
};
|
|
762
|
+
for (const [key, value] of Object.entries(filters2)) {
|
|
763
|
+
if (isAttribute(key)) {
|
|
764
|
+
const attribute = attributes2[key];
|
|
765
|
+
if (virtualScalarAttributes.includes(key) || isStrapiScalar(attribute)) {
|
|
766
|
+
resultMap[key] = recursivelyReplaceScalarOperators(value);
|
|
767
|
+
} else if (isRelation(attribute) || isMedia(attribute)) {
|
|
768
|
+
const relModel = strapi2.getModel(attribute.target);
|
|
769
|
+
resultMap[key] = this.graphQLFiltersToStrapiQuery(value, relModel);
|
|
770
|
+
} else if (isComponent(attribute)) {
|
|
771
|
+
const componentModel = strapi2.getModel(attribute.component);
|
|
772
|
+
resultMap[key] = this.graphQLFiltersToStrapiQuery(value, componentModel);
|
|
773
|
+
}
|
|
774
|
+
} else {
|
|
775
|
+
const rootLevelOperator = ROOT_LEVEL_OPERATORS.find(propEq("fieldName", key));
|
|
776
|
+
if (rootLevelOperator) {
|
|
777
|
+
const { strapiOperator } = rootLevelOperator;
|
|
778
|
+
resultMap[strapiOperator] = this.graphQLFiltersToStrapiQuery(value, contentType2);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return resultMap;
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
};
|
|
786
|
+
const graphqlScalarToOperators = ({ strapi: strapi2 }) => ({
|
|
787
|
+
graphqlScalarToOperators(graphqlScalar) {
|
|
788
|
+
const { GRAPHQL_SCALAR_OPERATORS: GRAPHQL_SCALAR_OPERATORS2 } = strapi2.plugin("graphql").service("constants");
|
|
789
|
+
const { operators: operators2 } = strapi2.plugin("graphql").service("builders").filters;
|
|
790
|
+
const associations = mapValues(
|
|
791
|
+
map((operatorName) => operators2[operatorName]),
|
|
792
|
+
GRAPHQL_SCALAR_OPERATORS2
|
|
793
|
+
);
|
|
794
|
+
return get(graphqlScalar, associations);
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
const entityToResponseEntity = (entity2) => ({
|
|
798
|
+
id: entity2.id,
|
|
799
|
+
attributes: entity2
|
|
800
|
+
});
|
|
801
|
+
const entitiesToResponseEntities = map(entityToResponseEntity);
|
|
802
|
+
const entityToResponseEntity$1 = () => ({
|
|
803
|
+
entityToResponseEntity,
|
|
804
|
+
entitiesToResponseEntities
|
|
805
|
+
});
|
|
806
|
+
const mappers = (context) => ({
|
|
807
|
+
...strapiScalarToGraphQLScalar(context),
|
|
808
|
+
...graphQLFiltersToStrapiQuery(context),
|
|
809
|
+
...graphqlScalarToOperators(context),
|
|
810
|
+
...entityToResponseEntity$1()
|
|
811
|
+
});
|
|
812
|
+
const attributes = ({ strapi: strapi2 }) => {
|
|
813
|
+
const isStrapiScalar = (attribute) => {
|
|
814
|
+
return strapi2.plugin("graphql").service("constants").STRAPI_SCALARS.includes(attribute.type);
|
|
815
|
+
};
|
|
816
|
+
const isGraphQLScalar = (attribute) => {
|
|
817
|
+
return strapi2.plugin("graphql").service("constants").GRAPHQL_SCALARS.includes(attribute.type);
|
|
818
|
+
};
|
|
819
|
+
const isMorphRelation = (attribute) => {
|
|
820
|
+
return attribute.type === "relation" && attribute.relation.includes("morph");
|
|
821
|
+
};
|
|
822
|
+
const isMedia = propEq("type", "media");
|
|
823
|
+
const isRelation = propEq("type", "relation");
|
|
824
|
+
const isEnumeration = propEq("type", "enumeration");
|
|
825
|
+
const isComponent = propEq("type", "component");
|
|
826
|
+
const isDynamicZone = propEq("type", "dynamiczone");
|
|
827
|
+
return {
|
|
828
|
+
isStrapiScalar,
|
|
829
|
+
isGraphQLScalar,
|
|
830
|
+
isMorphRelation,
|
|
831
|
+
isMedia,
|
|
832
|
+
isRelation,
|
|
833
|
+
isEnumeration,
|
|
834
|
+
isComponent,
|
|
835
|
+
isDynamicZone
|
|
836
|
+
};
|
|
837
|
+
};
|
|
838
|
+
const { ApplicationError: ApplicationError$2 } = errors;
|
|
839
|
+
const naming = ({ strapi: strapi2 }) => {
|
|
840
|
+
const getEnumName = (contentType2, attributeName) => {
|
|
841
|
+
const { attributes: attributes2 } = contentType2;
|
|
842
|
+
const { enumName } = attributes2[attributeName];
|
|
843
|
+
const { modelType } = contentType2;
|
|
844
|
+
const typeName = modelType === "component" ? getComponentName(contentType2) : getTypeName(contentType2);
|
|
845
|
+
const defaultEnumName = `ENUM_${typeName.toUpperCase()}_${attributeName.toUpperCase()}`;
|
|
846
|
+
return enumName || defaultEnumName;
|
|
847
|
+
};
|
|
848
|
+
const getTypeName = (contentType2, {
|
|
849
|
+
plurality = "singular"
|
|
850
|
+
} = {}) => {
|
|
851
|
+
const plugin = get("plugin", contentType2);
|
|
852
|
+
const modelName = get("modelName", contentType2);
|
|
853
|
+
const name = plurality === "singular" ? get("info.singularName", contentType2) : get("info.pluralName", contentType2);
|
|
854
|
+
const transformedPlugin = upperFirst(camelCase(plugin));
|
|
855
|
+
const transformedModelName = upperFirst(camelCase(name || singular(modelName)));
|
|
856
|
+
return `${transformedPlugin}${transformedModelName}`;
|
|
857
|
+
};
|
|
858
|
+
const getEntityName = (contentType2) => {
|
|
859
|
+
return `${getTypeName(contentType2)}Entity`;
|
|
860
|
+
};
|
|
861
|
+
const getEntityMetaName = (contentType2) => {
|
|
862
|
+
return `${getEntityName(contentType2)}Meta`;
|
|
863
|
+
};
|
|
864
|
+
const getEntityResponseName = (contentType2) => {
|
|
865
|
+
return `${getEntityName(contentType2)}Response`;
|
|
866
|
+
};
|
|
867
|
+
const getEntityResponseCollectionName = (contentType2) => {
|
|
868
|
+
return `${getEntityName(contentType2)}ResponseCollection`;
|
|
869
|
+
};
|
|
870
|
+
const getRelationResponseCollectionName = (contentType2) => {
|
|
871
|
+
return `${getTypeName(contentType2)}RelationResponseCollection`;
|
|
872
|
+
};
|
|
873
|
+
const getComponentName = (contentType2) => {
|
|
874
|
+
return contentType2.globalId;
|
|
875
|
+
};
|
|
876
|
+
const getComponentNameFromAttribute = (attribute) => {
|
|
877
|
+
return strapi2.components[attribute.component].globalId;
|
|
878
|
+
};
|
|
879
|
+
const getDynamicZoneName = (contentType2, attributeName) => {
|
|
880
|
+
const typeName = getTypeName(contentType2);
|
|
881
|
+
const dzName = upperFirst(camelCase(attributeName));
|
|
882
|
+
const suffix = "DynamicZone";
|
|
883
|
+
return `${typeName}${dzName}${suffix}`;
|
|
884
|
+
};
|
|
885
|
+
const getDynamicZoneInputName = (contentType2, attributeName) => {
|
|
886
|
+
const dzName = getDynamicZoneName(contentType2, attributeName);
|
|
887
|
+
return `${dzName}Input`;
|
|
888
|
+
};
|
|
889
|
+
const getComponentInputName = (contentType2) => {
|
|
890
|
+
const componentName = getComponentName(contentType2);
|
|
891
|
+
return `${componentName}Input`;
|
|
892
|
+
};
|
|
893
|
+
const getContentTypeInputName = (contentType2) => {
|
|
894
|
+
const typeName = getTypeName(contentType2);
|
|
895
|
+
return `${typeName}Input`;
|
|
896
|
+
};
|
|
897
|
+
const getEntityQueriesTypeName = (contentType2) => {
|
|
898
|
+
return `${getEntityName(contentType2)}Queries`;
|
|
899
|
+
};
|
|
900
|
+
const getEntityMutationsTypeName = (contentType2) => {
|
|
901
|
+
return `${getEntityName(contentType2)}Mutations`;
|
|
902
|
+
};
|
|
903
|
+
const getFiltersInputTypeName = (contentType2) => {
|
|
904
|
+
const isComponent = contentType2.modelType === "component";
|
|
905
|
+
const baseName = isComponent ? getComponentName(contentType2) : getTypeName(contentType2);
|
|
906
|
+
return `${baseName}FiltersInput`;
|
|
907
|
+
};
|
|
908
|
+
const getScalarFilterInputTypeName = (scalarType2) => {
|
|
909
|
+
return `${scalarType2}FilterInput`;
|
|
910
|
+
};
|
|
911
|
+
const getMorphRelationTypeName = (contentType2, attributeName) => {
|
|
912
|
+
const typeName = getTypeName(contentType2);
|
|
913
|
+
const formattedAttr = upperFirst(camelCase(attributeName));
|
|
914
|
+
return `${typeName}${formattedAttr}Morph`;
|
|
915
|
+
};
|
|
916
|
+
const buildCustomTypeNameGenerator = (options) => {
|
|
917
|
+
const { prefix = "", suffix = "", plurality = "singular", firstLetterCase = "upper" } = options;
|
|
918
|
+
if (!["plural", "singular"].includes(plurality)) {
|
|
919
|
+
throw new ApplicationError$2(
|
|
920
|
+
`"plurality" param must be either "plural" or "singular", but got: "${plurality}"`
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
const getCustomTypeName = pipe(
|
|
924
|
+
(ct) => getTypeName(ct, { plurality }),
|
|
925
|
+
firstLetterCase === "upper" ? upperFirst : lowerFirst
|
|
926
|
+
);
|
|
927
|
+
return (contentType2) => `${prefix}${getCustomTypeName(contentType2)}${suffix}`;
|
|
928
|
+
};
|
|
929
|
+
const getFindQueryName = buildCustomTypeNameGenerator({
|
|
930
|
+
plurality: "plural",
|
|
931
|
+
firstLetterCase: "lower"
|
|
932
|
+
});
|
|
933
|
+
const getFindOneQueryName = buildCustomTypeNameGenerator({ firstLetterCase: "lower" });
|
|
934
|
+
const getCreateMutationTypeName = buildCustomTypeNameGenerator({
|
|
935
|
+
prefix: "create",
|
|
936
|
+
firstLetterCase: "upper"
|
|
937
|
+
});
|
|
938
|
+
const getUpdateMutationTypeName = buildCustomTypeNameGenerator({
|
|
939
|
+
prefix: "update",
|
|
940
|
+
firstLetterCase: "upper"
|
|
941
|
+
});
|
|
942
|
+
const getDeleteMutationTypeName = buildCustomTypeNameGenerator({
|
|
943
|
+
prefix: "delete",
|
|
944
|
+
firstLetterCase: "upper"
|
|
945
|
+
});
|
|
946
|
+
return {
|
|
947
|
+
getEnumName,
|
|
948
|
+
getTypeName,
|
|
949
|
+
getEntityName,
|
|
950
|
+
getEntityMetaName,
|
|
951
|
+
getEntityResponseName,
|
|
952
|
+
getEntityResponseCollectionName,
|
|
953
|
+
getRelationResponseCollectionName,
|
|
954
|
+
getComponentName,
|
|
955
|
+
getComponentNameFromAttribute,
|
|
956
|
+
getDynamicZoneName,
|
|
957
|
+
getDynamicZoneInputName,
|
|
958
|
+
getComponentInputName,
|
|
959
|
+
getContentTypeInputName,
|
|
960
|
+
getEntityQueriesTypeName,
|
|
961
|
+
getEntityMutationsTypeName,
|
|
962
|
+
getFiltersInputTypeName,
|
|
963
|
+
getScalarFilterInputTypeName,
|
|
964
|
+
getMorphRelationTypeName,
|
|
965
|
+
buildCustomTypeNameGenerator,
|
|
966
|
+
getFindQueryName,
|
|
967
|
+
getFindOneQueryName,
|
|
968
|
+
getCreateMutationTypeName,
|
|
969
|
+
getUpdateMutationTypeName,
|
|
970
|
+
getDeleteMutationTypeName
|
|
971
|
+
};
|
|
972
|
+
};
|
|
973
|
+
const utils$1 = (context) => ({
|
|
974
|
+
naming: naming(context),
|
|
975
|
+
attributes: attributes(context),
|
|
976
|
+
mappers: mappers(context)
|
|
977
|
+
});
|
|
978
|
+
const PAGINATION_TYPE_NAME = "Pagination";
|
|
979
|
+
const PUBLICATION_STATE_TYPE_NAME = "PublicationState";
|
|
980
|
+
const ERROR_TYPE_NAME = "Error";
|
|
981
|
+
const RESPONSE_COLLECTION_META_TYPE_NAME = "ResponseCollectionMeta";
|
|
982
|
+
const GRAPHQL_SCALARS = [
|
|
983
|
+
"ID",
|
|
984
|
+
"Boolean",
|
|
985
|
+
"Int",
|
|
986
|
+
"String",
|
|
987
|
+
"Long",
|
|
988
|
+
"Float",
|
|
989
|
+
"JSON",
|
|
990
|
+
"Date",
|
|
991
|
+
"Time",
|
|
992
|
+
"DateTime"
|
|
993
|
+
];
|
|
994
|
+
const STRAPI_SCALARS = [
|
|
995
|
+
"boolean",
|
|
996
|
+
"integer",
|
|
997
|
+
"string",
|
|
998
|
+
"richtext",
|
|
999
|
+
"blocks",
|
|
1000
|
+
"enumeration",
|
|
1001
|
+
"biginteger",
|
|
1002
|
+
"float",
|
|
1003
|
+
"decimal",
|
|
1004
|
+
"json",
|
|
1005
|
+
"date",
|
|
1006
|
+
"time",
|
|
1007
|
+
"datetime",
|
|
1008
|
+
"timestamp",
|
|
1009
|
+
"uid",
|
|
1010
|
+
"email",
|
|
1011
|
+
"password",
|
|
1012
|
+
"text"
|
|
1013
|
+
];
|
|
1014
|
+
const SCALARS_ASSOCIATIONS = {
|
|
1015
|
+
uid: "String",
|
|
1016
|
+
email: "String",
|
|
1017
|
+
password: "String",
|
|
1018
|
+
text: "String",
|
|
1019
|
+
boolean: "Boolean",
|
|
1020
|
+
integer: "Int",
|
|
1021
|
+
string: "String",
|
|
1022
|
+
enumeration: "String",
|
|
1023
|
+
richtext: "String",
|
|
1024
|
+
blocks: "JSON",
|
|
1025
|
+
biginteger: "Long",
|
|
1026
|
+
float: "Float",
|
|
1027
|
+
decimal: "Float",
|
|
1028
|
+
json: "JSON",
|
|
1029
|
+
date: "Date",
|
|
1030
|
+
time: "Time",
|
|
1031
|
+
datetime: "DateTime",
|
|
1032
|
+
timestamp: "DateTime"
|
|
1033
|
+
};
|
|
1034
|
+
const GENERIC_MORPH_TYPENAME = "GenericMorph";
|
|
1035
|
+
const KINDS = {
|
|
1036
|
+
type: "type",
|
|
1037
|
+
component: "component",
|
|
1038
|
+
dynamicZone: "dynamic-zone",
|
|
1039
|
+
enum: "enum",
|
|
1040
|
+
entity: "entity",
|
|
1041
|
+
entityResponse: "entity-response",
|
|
1042
|
+
entityResponseCollection: "entity-response-collection",
|
|
1043
|
+
relationResponseCollection: "relation-response-collection",
|
|
1044
|
+
query: "query",
|
|
1045
|
+
mutation: "mutation",
|
|
1046
|
+
input: "input",
|
|
1047
|
+
filtersInput: "filters-input",
|
|
1048
|
+
scalar: "scalar",
|
|
1049
|
+
morph: "polymorphic",
|
|
1050
|
+
internal: "internal"
|
|
1051
|
+
};
|
|
1052
|
+
const allOperators = [
|
|
1053
|
+
"and",
|
|
1054
|
+
"or",
|
|
1055
|
+
"not",
|
|
1056
|
+
"eq",
|
|
1057
|
+
"eqi",
|
|
1058
|
+
"ne",
|
|
1059
|
+
"nei",
|
|
1060
|
+
"startsWith",
|
|
1061
|
+
"endsWith",
|
|
1062
|
+
"contains",
|
|
1063
|
+
"notContains",
|
|
1064
|
+
"containsi",
|
|
1065
|
+
"notContainsi",
|
|
1066
|
+
"gt",
|
|
1067
|
+
"gte",
|
|
1068
|
+
"lt",
|
|
1069
|
+
"lte",
|
|
1070
|
+
"null",
|
|
1071
|
+
"notNull",
|
|
1072
|
+
"in",
|
|
1073
|
+
"notIn",
|
|
1074
|
+
"between"
|
|
1075
|
+
];
|
|
1076
|
+
const GRAPHQL_SCALAR_OPERATORS = {
|
|
1077
|
+
// ID
|
|
1078
|
+
ID: allOperators,
|
|
1079
|
+
// Booleans
|
|
1080
|
+
Boolean: allOperators,
|
|
1081
|
+
// Strings
|
|
1082
|
+
String: allOperators,
|
|
1083
|
+
// Numbers
|
|
1084
|
+
Int: allOperators,
|
|
1085
|
+
Long: allOperators,
|
|
1086
|
+
Float: allOperators,
|
|
1087
|
+
// Dates
|
|
1088
|
+
Date: allOperators,
|
|
1089
|
+
Time: allOperators,
|
|
1090
|
+
DateTime: allOperators,
|
|
1091
|
+
// Others
|
|
1092
|
+
JSON: allOperators
|
|
1093
|
+
};
|
|
1094
|
+
const ERROR_CODES = {
|
|
1095
|
+
emptyDynamicZone: "dynamiczone.empty"
|
|
1096
|
+
};
|
|
1097
|
+
const constants = () => ({
|
|
1098
|
+
PAGINATION_TYPE_NAME,
|
|
1099
|
+
RESPONSE_COLLECTION_META_TYPE_NAME,
|
|
1100
|
+
PUBLICATION_STATE_TYPE_NAME,
|
|
1101
|
+
GRAPHQL_SCALARS,
|
|
1102
|
+
STRAPI_SCALARS,
|
|
1103
|
+
GENERIC_MORPH_TYPENAME,
|
|
1104
|
+
KINDS,
|
|
1105
|
+
GRAPHQL_SCALAR_OPERATORS,
|
|
1106
|
+
SCALARS_ASSOCIATIONS,
|
|
1107
|
+
ERROR_CODES,
|
|
1108
|
+
ERROR_TYPE_NAME
|
|
1109
|
+
});
|
|
1110
|
+
const SortArg = arg({
|
|
1111
|
+
type: list("String"),
|
|
1112
|
+
default: []
|
|
1113
|
+
});
|
|
1114
|
+
const publicationState$1 = ({ strapi: strapi2 }) => {
|
|
1115
|
+
const { PUBLICATION_STATE_TYPE_NAME: PUBLICATION_STATE_TYPE_NAME2 } = strapi2.plugin("graphql").service("constants");
|
|
1116
|
+
return arg({
|
|
1117
|
+
type: PUBLICATION_STATE_TYPE_NAME2,
|
|
1118
|
+
default: "live"
|
|
1119
|
+
});
|
|
1120
|
+
};
|
|
1121
|
+
const PaginationInputType = inputObjectType({
|
|
1122
|
+
name: "PaginationArg",
|
|
1123
|
+
definition(t) {
|
|
1124
|
+
t.int("page");
|
|
1125
|
+
t.int("pageSize");
|
|
1126
|
+
t.int("start");
|
|
1127
|
+
t.int("limit");
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
const PaginationArg = arg({
|
|
1131
|
+
type: PaginationInputType,
|
|
1132
|
+
default: {}
|
|
1133
|
+
});
|
|
1134
|
+
const args = (context) => ({
|
|
1135
|
+
SortArg,
|
|
1136
|
+
PaginationArg,
|
|
1137
|
+
PublicationStateArg: publicationState$1(context)
|
|
1138
|
+
});
|
|
1139
|
+
const { ValidationError: ValidationError$2 } = errors;
|
|
1140
|
+
const TimeScalar = new GraphQLScalarType({
|
|
1141
|
+
name: "Time",
|
|
1142
|
+
description: "A time string with format HH:mm:ss.SSS",
|
|
1143
|
+
serialize(value) {
|
|
1144
|
+
return parseType({ type: "time", value });
|
|
1145
|
+
},
|
|
1146
|
+
parseValue(value) {
|
|
1147
|
+
return parseType({ type: "time", value });
|
|
1148
|
+
},
|
|
1149
|
+
parseLiteral(ast) {
|
|
1150
|
+
if (ast.kind !== Kind.STRING) {
|
|
1151
|
+
throw new ValidationError$2("Time cannot represent non string type");
|
|
1152
|
+
}
|
|
1153
|
+
const { value } = ast;
|
|
1154
|
+
return parseType({ type: "time", value });
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
const parseAndCast = (parseFn) => (...args2) => {
|
|
1158
|
+
const parsedValue = parseFn(...args2);
|
|
1159
|
+
if (parsedValue instanceof Date) {
|
|
1160
|
+
return parsedValue.toISOString().split("T")[0];
|
|
1161
|
+
}
|
|
1162
|
+
return parsedValue;
|
|
1163
|
+
};
|
|
1164
|
+
GraphQLDate.parseValue = parseAndCast(GraphQLDate.parseValue);
|
|
1165
|
+
GraphQLDate.parseLiteral = parseAndCast(GraphQLDate.parseLiteral);
|
|
1166
|
+
const scalars = () => ({
|
|
1167
|
+
JSON: asNexusMethod(GraphQLJSON, "json"),
|
|
1168
|
+
DateTime: asNexusMethod(GraphQLDateTime, "dateTime"),
|
|
1169
|
+
Time: asNexusMethod(TimeScalar, "time"),
|
|
1170
|
+
Date: asNexusMethod(GraphQLDate, "date"),
|
|
1171
|
+
Long: asNexusMethod(GraphQLLong, "long"),
|
|
1172
|
+
Upload: asNexusMethod(GraphQLUpload, "upload")
|
|
1173
|
+
});
|
|
1174
|
+
const pagination = ({ strapi: strapi2 }) => {
|
|
1175
|
+
const { PAGINATION_TYPE_NAME: PAGINATION_TYPE_NAME2 } = strapi2.plugin("graphql").service("constants");
|
|
1176
|
+
return {
|
|
1177
|
+
/**
|
|
1178
|
+
* Type definition for a Pagination object
|
|
1179
|
+
* @type {NexusObjectTypeDef}
|
|
1180
|
+
*/
|
|
1181
|
+
Pagination: objectType({
|
|
1182
|
+
name: PAGINATION_TYPE_NAME2,
|
|
1183
|
+
definition(t) {
|
|
1184
|
+
t.nonNull.int("total");
|
|
1185
|
+
t.nonNull.int("page");
|
|
1186
|
+
t.nonNull.int("pageSize");
|
|
1187
|
+
t.nonNull.int("pageCount");
|
|
1188
|
+
}
|
|
1189
|
+
})
|
|
1190
|
+
};
|
|
1191
|
+
};
|
|
1192
|
+
const buildResponseCollectionMeta = ({ strapi: strapi2 }) => {
|
|
1193
|
+
const { RESPONSE_COLLECTION_META_TYPE_NAME: RESPONSE_COLLECTION_META_TYPE_NAME2, PAGINATION_TYPE_NAME: PAGINATION_TYPE_NAME2 } = strapi2.plugin("graphql").service("constants");
|
|
1194
|
+
return {
|
|
1195
|
+
/**
|
|
1196
|
+
* A shared type definition used in EntitiesResponseCollection
|
|
1197
|
+
* to have information about the collection as a whole
|
|
1198
|
+
* @type {NexusObjectTypeDef}
|
|
1199
|
+
*/
|
|
1200
|
+
ResponseCollectionMeta: objectType({
|
|
1201
|
+
name: RESPONSE_COLLECTION_META_TYPE_NAME2,
|
|
1202
|
+
definition(t) {
|
|
1203
|
+
t.nonNull.field("pagination", {
|
|
1204
|
+
type: PAGINATION_TYPE_NAME2,
|
|
1205
|
+
async resolve(parent, _childArgs, ctx) {
|
|
1206
|
+
const { args: args2, resourceUID } = parent;
|
|
1207
|
+
const { start, limit } = args2;
|
|
1208
|
+
const safeLimit = Math.max(limit, 1);
|
|
1209
|
+
const contentType2 = strapi2.getModel(resourceUID);
|
|
1210
|
+
await validate.contentAPI.query(args2, contentType2, {
|
|
1211
|
+
auth: ctx?.state?.auth
|
|
1212
|
+
});
|
|
1213
|
+
const sanitizedQuery = await sanitize.contentAPI.query(args2, contentType2, {
|
|
1214
|
+
auth: ctx?.state?.auth
|
|
1215
|
+
});
|
|
1216
|
+
const total = await strapi2.entityService.count(resourceUID, sanitizedQuery);
|
|
1217
|
+
const pageSize = limit === -1 ? total - start : safeLimit;
|
|
1218
|
+
const pageCount = limit === -1 ? safeLimit : Math.ceil(total / safeLimit);
|
|
1219
|
+
const page = limit === -1 ? safeLimit : Math.floor(start / safeLimit) + 1;
|
|
1220
|
+
return { total, page, pageSize, pageCount };
|
|
1221
|
+
}
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
})
|
|
1225
|
+
};
|
|
1226
|
+
};
|
|
1227
|
+
const publicationState = ({ strapi: strapi2 }) => {
|
|
1228
|
+
const { PUBLICATION_STATE_TYPE_NAME: PUBLICATION_STATE_TYPE_NAME2 } = strapi2.plugin("graphql").service("constants");
|
|
1229
|
+
return {
|
|
1230
|
+
/**
|
|
1231
|
+
* An enum type definition representing a publication state
|
|
1232
|
+
* @type {NexusEnumTypeDef}
|
|
1233
|
+
*/
|
|
1234
|
+
PublicationState: enumType({
|
|
1235
|
+
name: PUBLICATION_STATE_TYPE_NAME2,
|
|
1236
|
+
members: {
|
|
1237
|
+
// Published only
|
|
1238
|
+
LIVE: "live",
|
|
1239
|
+
// Published & draft
|
|
1240
|
+
PREVIEW: "preview"
|
|
1241
|
+
}
|
|
1242
|
+
})
|
|
1243
|
+
};
|
|
1244
|
+
};
|
|
1245
|
+
const buildScalarFilters = ({ strapi: strapi2 }) => {
|
|
1246
|
+
const { naming: naming2, mappers: mappers2 } = strapi2.plugin("graphql").service("utils");
|
|
1247
|
+
const { helpers: helpers2 } = strapi2.plugin("graphql").service("internals");
|
|
1248
|
+
return helpers2.getEnabledScalars().reduce((acc, type) => {
|
|
1249
|
+
const operators2 = mappers2.graphqlScalarToOperators(type);
|
|
1250
|
+
const typeName = naming2.getScalarFilterInputTypeName(type);
|
|
1251
|
+
if (!operators2 || operators2.length === 0) {
|
|
1252
|
+
return acc;
|
|
1253
|
+
}
|
|
1254
|
+
return {
|
|
1255
|
+
...acc,
|
|
1256
|
+
[typeName]: inputObjectType({
|
|
1257
|
+
name: typeName,
|
|
1258
|
+
definition(t) {
|
|
1259
|
+
for (const operator of operators2) {
|
|
1260
|
+
operator.add(t, type);
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
})
|
|
1264
|
+
};
|
|
1265
|
+
}, {});
|
|
1266
|
+
};
|
|
1267
|
+
const filters$1 = (context) => ({
|
|
1268
|
+
scalars: buildScalarFilters(context)
|
|
1269
|
+
});
|
|
1270
|
+
const { ValidationError: ValidationError$1 } = errors;
|
|
1271
|
+
const error = ({ strapi: strapi2 }) => {
|
|
1272
|
+
const { ERROR_CODES: ERROR_CODES2, ERROR_TYPE_NAME: ERROR_TYPE_NAME2 } = strapi2.plugin("graphql").service("constants");
|
|
1273
|
+
return objectType({
|
|
1274
|
+
name: ERROR_TYPE_NAME2,
|
|
1275
|
+
definition(t) {
|
|
1276
|
+
t.nonNull.string("code", {
|
|
1277
|
+
resolve(parent) {
|
|
1278
|
+
const code = get("code", parent);
|
|
1279
|
+
const isValidPlaceholderCode = Object.values(ERROR_CODES2).includes(code);
|
|
1280
|
+
if (!isValidPlaceholderCode) {
|
|
1281
|
+
throw new ValidationError$1(`"${code}" is not a valid code value`);
|
|
1282
|
+
}
|
|
1283
|
+
return code;
|
|
1284
|
+
}
|
|
1285
|
+
});
|
|
1286
|
+
t.string("message");
|
|
1287
|
+
}
|
|
1288
|
+
});
|
|
1289
|
+
};
|
|
1290
|
+
const types = (context) => () => {
|
|
1291
|
+
const { strapi: strapi2 } = context;
|
|
1292
|
+
const { KINDS: KINDS2 } = strapi2.plugin("graphql").service("constants");
|
|
1293
|
+
return {
|
|
1294
|
+
[KINDS2.internal]: {
|
|
1295
|
+
error: error(context),
|
|
1296
|
+
pagination: pagination(context),
|
|
1297
|
+
responseCollectionMeta: buildResponseCollectionMeta(context)
|
|
1298
|
+
},
|
|
1299
|
+
[KINDS2.enum]: {
|
|
1300
|
+
publicationState: publicationState(context)
|
|
1301
|
+
},
|
|
1302
|
+
[KINDS2.filtersInput]: {
|
|
1303
|
+
...filters$1(context)
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
};
|
|
1307
|
+
const getEnabledScalars = ({ strapi: strapi2 }) => () => {
|
|
1308
|
+
const { GRAPHQL_SCALAR_OPERATORS: GRAPHQL_SCALAR_OPERATORS2 } = strapi2.plugin("graphql").service("constants");
|
|
1309
|
+
return Object.entries(GRAPHQL_SCALAR_OPERATORS2).filter(([, value]) => value.length > 0).map(first);
|
|
1310
|
+
};
|
|
1311
|
+
const helpers = (context) => ({
|
|
1312
|
+
getEnabledScalars: getEnabledScalars(context)
|
|
1313
|
+
});
|
|
1314
|
+
const internals = (context) => ({
|
|
1315
|
+
args: args(context),
|
|
1316
|
+
scalars: scalars(),
|
|
1317
|
+
buildInternalTypes: types(context),
|
|
1318
|
+
helpers: helpers(context)
|
|
1319
|
+
});
|
|
1320
|
+
const buildEnumTypeDefinition = (definition, name) => {
|
|
1321
|
+
return enumType({
|
|
1322
|
+
name,
|
|
1323
|
+
members: definition.enum.reduce(
|
|
1324
|
+
(acc, value) => set(toRegressedEnumValue(value), value, acc),
|
|
1325
|
+
{}
|
|
1326
|
+
)
|
|
1327
|
+
});
|
|
1328
|
+
};
|
|
1329
|
+
const enums = () => ({
|
|
1330
|
+
buildEnumTypeDefinition
|
|
1331
|
+
});
|
|
1332
|
+
const { ApplicationError: ApplicationError$1 } = errors;
|
|
1333
|
+
const dynamicZone = ({ strapi: strapi2 }) => {
|
|
1334
|
+
const buildTypeDefinition = (name, components) => {
|
|
1335
|
+
const { ERROR_TYPE_NAME: ERROR_TYPE_NAME2 } = strapi2.plugin("graphql").service("constants");
|
|
1336
|
+
const isEmpty2 = components.length === 0;
|
|
1337
|
+
const componentsTypeNames = components.map((componentUID) => {
|
|
1338
|
+
const component = strapi2.components[componentUID];
|
|
1339
|
+
if (!component) {
|
|
1340
|
+
throw new ApplicationError$1(
|
|
1341
|
+
`Trying to create a dynamic zone type with an unknown component: "${componentUID}"`
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
return component.globalId;
|
|
1345
|
+
});
|
|
1346
|
+
return unionType({
|
|
1347
|
+
name,
|
|
1348
|
+
resolveType(obj) {
|
|
1349
|
+
if (isEmpty2) {
|
|
1350
|
+
return ERROR_TYPE_NAME2;
|
|
1351
|
+
}
|
|
1352
|
+
return strapi2.components[obj.__component].globalId;
|
|
1353
|
+
},
|
|
1354
|
+
definition(t) {
|
|
1355
|
+
t.members(...componentsTypeNames, ERROR_TYPE_NAME2);
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
};
|
|
1359
|
+
const buildInputDefinition = (name, components) => {
|
|
1360
|
+
const parseData = (value) => {
|
|
1361
|
+
const component = Object.values(strapi2.components).find(
|
|
1362
|
+
(component2) => component2.globalId === value.__typename
|
|
1363
|
+
);
|
|
1364
|
+
if (!component) {
|
|
1365
|
+
throw new ApplicationError$1(
|
|
1366
|
+
`Component not found. expected one of: ${components.map((uid) => strapi2.components[uid].globalId).join(", ")}`
|
|
1367
|
+
);
|
|
1368
|
+
}
|
|
1369
|
+
return {
|
|
1370
|
+
__component: component.uid,
|
|
1371
|
+
...omit(["__typename"], value)
|
|
1372
|
+
};
|
|
1373
|
+
};
|
|
1374
|
+
return scalarType({
|
|
1375
|
+
name,
|
|
1376
|
+
serialize: (value) => value,
|
|
1377
|
+
parseValue: (value) => parseData(value),
|
|
1378
|
+
parseLiteral(ast, variables) {
|
|
1379
|
+
if (ast.kind !== Kind.OBJECT) {
|
|
1380
|
+
return void 0;
|
|
1381
|
+
}
|
|
1382
|
+
const value = valueFromASTUntyped(ast, variables);
|
|
1383
|
+
return parseData(value);
|
|
1384
|
+
}
|
|
1385
|
+
});
|
|
1386
|
+
};
|
|
1387
|
+
return {
|
|
1388
|
+
/**
|
|
1389
|
+
* Build a Nexus dynamic zone type from a Strapi dz attribute
|
|
1390
|
+
* @param {object} definition - The definition of the dynamic zone
|
|
1391
|
+
* @param {string} name - the name of the dynamic zone
|
|
1392
|
+
* @param {string} inputName - the name of the dynamic zone's input
|
|
1393
|
+
* @return {[NexusUnionTypeDef, NexusScalarTypeDef]}
|
|
1394
|
+
*/
|
|
1395
|
+
buildDynamicZoneDefinition(definition, name, inputName) {
|
|
1396
|
+
const { components } = definition;
|
|
1397
|
+
const typeDefinition = buildTypeDefinition(name, components);
|
|
1398
|
+
const inputDefinition = buildInputDefinition(inputName, components);
|
|
1399
|
+
return [typeDefinition, inputDefinition];
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1402
|
+
};
|
|
1403
|
+
const entity = ({ strapi: strapi2 }) => {
|
|
1404
|
+
const { naming: naming2 } = strapi2.plugin("graphql").service("utils");
|
|
1405
|
+
return {
|
|
1406
|
+
/**
|
|
1407
|
+
* Build a higher level type for a content type which contains the attributes, the ID and the metadata
|
|
1408
|
+
* @param {object} contentType The content type which will be used to build its entity type
|
|
1409
|
+
* @return {NexusObjectTypeDef}
|
|
1410
|
+
*/
|
|
1411
|
+
buildEntityDefinition(contentType2) {
|
|
1412
|
+
const { attributes: attributes2 } = contentType2;
|
|
1413
|
+
const name = naming2.getEntityName(contentType2);
|
|
1414
|
+
const typeName = naming2.getTypeName(contentType2);
|
|
1415
|
+
return objectType({
|
|
1416
|
+
name,
|
|
1417
|
+
definition(t) {
|
|
1418
|
+
t.id("id", { resolve: prop("id") });
|
|
1419
|
+
if (!isEmpty(attributes2)) {
|
|
1420
|
+
t.field("attributes", {
|
|
1421
|
+
type: typeName,
|
|
1422
|
+
resolve: identity
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
};
|
|
1429
|
+
};
|
|
1430
|
+
function buildEntityMetaDefinition() {
|
|
1431
|
+
}
|
|
1432
|
+
const entityMeta = () => ({
|
|
1433
|
+
buildEntityMetaDefinition
|
|
1434
|
+
});
|
|
1435
|
+
const typeBuilder = (context) => {
|
|
1436
|
+
const { strapi: strapi2 } = context;
|
|
1437
|
+
const getGraphQLService = strapi2.plugin("graphql").service;
|
|
1438
|
+
const extension = getGraphQLService("extension");
|
|
1439
|
+
const addScalarAttribute = (options) => {
|
|
1440
|
+
const { builder, attributeName, attribute } = options;
|
|
1441
|
+
const { mappers: mappers2 } = getGraphQLService("utils");
|
|
1442
|
+
const gqlType = mappers2.strapiScalarToGraphQLScalar(attribute.type);
|
|
1443
|
+
builder.field(attributeName, { type: gqlType });
|
|
1444
|
+
};
|
|
1445
|
+
const addComponentAttribute = (options) => {
|
|
1446
|
+
const { builder, attributeName, contentType: contentType2, attribute } = options;
|
|
1447
|
+
let localBuilder = builder;
|
|
1448
|
+
const { naming: naming2 } = getGraphQLService("utils");
|
|
1449
|
+
const { getContentTypeArgs } = getGraphQLService("builders").utils;
|
|
1450
|
+
const { buildComponentResolver } = getGraphQLService("builders").get("content-api");
|
|
1451
|
+
const type = naming2.getComponentNameFromAttribute(attribute);
|
|
1452
|
+
if (attribute.repeatable) {
|
|
1453
|
+
localBuilder = localBuilder.list;
|
|
1454
|
+
}
|
|
1455
|
+
const targetComponent = strapi2.getModel(attribute.component);
|
|
1456
|
+
const resolve = buildComponentResolver({
|
|
1457
|
+
contentTypeUID: contentType2.uid,
|
|
1458
|
+
attributeName,
|
|
1459
|
+
strapi: strapi2
|
|
1460
|
+
});
|
|
1461
|
+
const args2 = getContentTypeArgs(targetComponent, { multiple: !!attribute.repeatable });
|
|
1462
|
+
localBuilder.field(attributeName, { type, resolve, args: args2 });
|
|
1463
|
+
};
|
|
1464
|
+
const addDynamicZoneAttribute = (options) => {
|
|
1465
|
+
const { builder, attributeName, contentType: contentType2 } = options;
|
|
1466
|
+
const { naming: naming2 } = getGraphQLService("utils");
|
|
1467
|
+
const { ERROR_CODES: ERROR_CODES2 } = getGraphQLService("constants");
|
|
1468
|
+
const { buildDynamicZoneResolver } = getGraphQLService("builders").get("content-api");
|
|
1469
|
+
const { components } = contentType2.attributes[attributeName];
|
|
1470
|
+
const isEmpty2 = components.length === 0;
|
|
1471
|
+
const type = naming2.getDynamicZoneName(contentType2, attributeName);
|
|
1472
|
+
const resolve = isEmpty2 ? (
|
|
1473
|
+
// If the dynamic zone don't have any component, then return an error payload
|
|
1474
|
+
constant({
|
|
1475
|
+
code: ERROR_CODES2.emptyDynamicZone,
|
|
1476
|
+
message: `This dynamic zone don't have any component attached to it`
|
|
1477
|
+
})
|
|
1478
|
+
) : (
|
|
1479
|
+
// Else, return a classic dynamic-zone resolver
|
|
1480
|
+
buildDynamicZoneResolver({
|
|
1481
|
+
contentTypeUID: contentType2.uid,
|
|
1482
|
+
attributeName
|
|
1483
|
+
})
|
|
1484
|
+
);
|
|
1485
|
+
builder.list.field(attributeName, { type, resolve });
|
|
1486
|
+
};
|
|
1487
|
+
const addEnumAttribute = (options) => {
|
|
1488
|
+
const { builder, attributeName, contentType: contentType2 } = options;
|
|
1489
|
+
const { naming: naming2 } = getGraphQLService("utils");
|
|
1490
|
+
const type = naming2.getEnumName(contentType2, attributeName);
|
|
1491
|
+
builder.field(attributeName, { type });
|
|
1492
|
+
};
|
|
1493
|
+
const addMediaAttribute = (options) => {
|
|
1494
|
+
const { naming: naming2 } = getGraphQLService("utils");
|
|
1495
|
+
const { getContentTypeArgs } = getGraphQLService("builders").utils;
|
|
1496
|
+
const { buildAssociationResolver } = getGraphQLService("builders").get("content-api");
|
|
1497
|
+
const extension2 = getGraphQLService("extension");
|
|
1498
|
+
const { builder } = options;
|
|
1499
|
+
const { attributeName, attribute, contentType: contentType2 } = options;
|
|
1500
|
+
const fileUID = "plugin::upload.file";
|
|
1501
|
+
if (extension2.shadowCRUD(fileUID).isDisabled()) {
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1504
|
+
const fileContentType = strapi2.contentTypes[fileUID];
|
|
1505
|
+
const resolve = buildAssociationResolver({
|
|
1506
|
+
contentTypeUID: contentType2.uid,
|
|
1507
|
+
attributeName,
|
|
1508
|
+
strapi: strapi2
|
|
1509
|
+
});
|
|
1510
|
+
const args2 = attribute.multiple ? getContentTypeArgs(fileContentType) : void 0;
|
|
1511
|
+
const type = attribute.multiple ? naming2.getRelationResponseCollectionName(fileContentType) : naming2.getEntityResponseName(fileContentType);
|
|
1512
|
+
builder.field(attributeName, { type, resolve, args: args2 });
|
|
1513
|
+
};
|
|
1514
|
+
const addPolymorphicRelationalAttribute = (options) => {
|
|
1515
|
+
const { GENERIC_MORPH_TYPENAME: GENERIC_MORPH_TYPENAME2 } = getGraphQLService("constants");
|
|
1516
|
+
const { naming: naming2 } = getGraphQLService("utils");
|
|
1517
|
+
const { buildAssociationResolver } = getGraphQLService("builders").get("content-api");
|
|
1518
|
+
let { builder } = options;
|
|
1519
|
+
const { attributeName, attribute, contentType: contentType2 } = options;
|
|
1520
|
+
const { target } = attribute;
|
|
1521
|
+
const isToManyRelation = attribute.relation.endsWith("Many");
|
|
1522
|
+
if (isToManyRelation) {
|
|
1523
|
+
builder = builder.list;
|
|
1524
|
+
}
|
|
1525
|
+
const resolve = buildAssociationResolver({
|
|
1526
|
+
contentTypeUID: contentType2.uid,
|
|
1527
|
+
attributeName,
|
|
1528
|
+
strapi: strapi2
|
|
1529
|
+
});
|
|
1530
|
+
if (isUndefined(target)) {
|
|
1531
|
+
builder.field(attributeName, {
|
|
1532
|
+
type: GENERIC_MORPH_TYPENAME2,
|
|
1533
|
+
resolve
|
|
1534
|
+
});
|
|
1535
|
+
} else if (isArray(target) && target.every(isString)) {
|
|
1536
|
+
const type = naming2.getMorphRelationTypeName(contentType2, attributeName);
|
|
1537
|
+
builder.field(attributeName, { type, resolve });
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
const addRegularRelationalAttribute = (options) => {
|
|
1541
|
+
const { naming: naming2 } = getGraphQLService("utils");
|
|
1542
|
+
const { getContentTypeArgs } = getGraphQLService("builders").utils;
|
|
1543
|
+
const { buildAssociationResolver } = getGraphQLService("builders").get("content-api");
|
|
1544
|
+
const extension2 = getGraphQLService("extension");
|
|
1545
|
+
const { builder } = options;
|
|
1546
|
+
const { attributeName, attribute, contentType: contentType2 } = options;
|
|
1547
|
+
if (extension2.shadowCRUD(attribute.target).isDisabled()) {
|
|
1548
|
+
return;
|
|
1549
|
+
}
|
|
1550
|
+
const isToManyRelation = attribute.relation.endsWith("Many");
|
|
1551
|
+
const resolve = buildAssociationResolver({
|
|
1552
|
+
contentTypeUID: contentType2.uid,
|
|
1553
|
+
attributeName,
|
|
1554
|
+
strapi: strapi2
|
|
1555
|
+
});
|
|
1556
|
+
const targetContentType = strapi2.getModel(attribute.target);
|
|
1557
|
+
const type = isToManyRelation ? naming2.getRelationResponseCollectionName(targetContentType) : naming2.getEntityResponseName(targetContentType);
|
|
1558
|
+
const args2 = isToManyRelation ? getContentTypeArgs(targetContentType) : void 0;
|
|
1559
|
+
const resolverPath = `${naming2.getTypeName(contentType2)}.${attributeName}`;
|
|
1560
|
+
const resolverScope = `${targetContentType.uid}.find`;
|
|
1561
|
+
extension2.use({ resolversConfig: { [resolverPath]: { auth: { scope: [resolverScope] } } } });
|
|
1562
|
+
builder.field(attributeName, { type, resolve, args: args2 });
|
|
1563
|
+
};
|
|
1564
|
+
const isNotPrivate = (contentType2) => (attributeName) => {
|
|
1565
|
+
return !contentTypes.isPrivateAttribute(contentType2, attributeName);
|
|
1566
|
+
};
|
|
1567
|
+
const isNotDisabled = (contentType2) => (attributeName) => {
|
|
1568
|
+
return extension.shadowCRUD(contentType2.uid).field(attributeName).hasOutputEnabled();
|
|
1569
|
+
};
|
|
1570
|
+
return {
|
|
1571
|
+
/**
|
|
1572
|
+
* Create a type definition for a given content type
|
|
1573
|
+
* @param contentType - The content type used to created the definition
|
|
1574
|
+
* @return {NexusObjectTypeDef}
|
|
1575
|
+
*/
|
|
1576
|
+
buildTypeDefinition(contentType2) {
|
|
1577
|
+
const utils2 = getGraphQLService("utils");
|
|
1578
|
+
const { getComponentName, getTypeName } = utils2.naming;
|
|
1579
|
+
const {
|
|
1580
|
+
isStrapiScalar,
|
|
1581
|
+
isComponent,
|
|
1582
|
+
isDynamicZone,
|
|
1583
|
+
isEnumeration,
|
|
1584
|
+
isMedia,
|
|
1585
|
+
isMorphRelation,
|
|
1586
|
+
isRelation
|
|
1587
|
+
} = utils2.attributes;
|
|
1588
|
+
const { attributes: attributes2, modelType } = contentType2;
|
|
1589
|
+
const attributesKey = Object.keys(attributes2);
|
|
1590
|
+
const name = (modelType === "component" ? getComponentName : getTypeName).call(
|
|
1591
|
+
null,
|
|
1592
|
+
contentType2
|
|
1593
|
+
);
|
|
1594
|
+
return objectType({
|
|
1595
|
+
name,
|
|
1596
|
+
definition(t) {
|
|
1597
|
+
if (modelType === "component" && isNotDisabled(contentType2)("id")) {
|
|
1598
|
+
t.nonNull.id("id");
|
|
1599
|
+
}
|
|
1600
|
+
attributesKey.filter(isNotPrivate(contentType2)).filter(isNotDisabled(contentType2)).forEach((attributeName) => {
|
|
1601
|
+
const attribute = attributes2[attributeName];
|
|
1602
|
+
let builder = t;
|
|
1603
|
+
if (attribute.required) {
|
|
1604
|
+
builder = builder.nonNull;
|
|
1605
|
+
}
|
|
1606
|
+
const options = {
|
|
1607
|
+
builder,
|
|
1608
|
+
attributeName,
|
|
1609
|
+
attribute,
|
|
1610
|
+
contentType: contentType2,
|
|
1611
|
+
context
|
|
1612
|
+
};
|
|
1613
|
+
if (isEnumeration(attribute)) {
|
|
1614
|
+
addEnumAttribute(options);
|
|
1615
|
+
} else if (isStrapiScalar(attribute)) {
|
|
1616
|
+
addScalarAttribute(options);
|
|
1617
|
+
} else if (isComponent(attribute)) {
|
|
1618
|
+
addComponentAttribute(options);
|
|
1619
|
+
} else if (isDynamicZone(attribute)) {
|
|
1620
|
+
addDynamicZoneAttribute(options);
|
|
1621
|
+
} else if (isMedia(attribute)) {
|
|
1622
|
+
addMediaAttribute(options);
|
|
1623
|
+
} else if (isMorphRelation(attribute)) {
|
|
1624
|
+
addPolymorphicRelationalAttribute(options);
|
|
1625
|
+
} else if (isRelation(attribute)) {
|
|
1626
|
+
addRegularRelationalAttribute(options);
|
|
1627
|
+
}
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
};
|
|
1633
|
+
};
|
|
1634
|
+
const response = ({ strapi: strapi2 }) => {
|
|
1635
|
+
const { naming: naming2 } = strapi2.plugin("graphql").service("utils");
|
|
1636
|
+
return {
|
|
1637
|
+
/**
|
|
1638
|
+
* Build a type definition for a content API response for a given content type
|
|
1639
|
+
*/
|
|
1640
|
+
buildResponseDefinition(contentType2) {
|
|
1641
|
+
const name = naming2.getEntityResponseName(contentType2);
|
|
1642
|
+
const entityName = naming2.getEntityName(contentType2);
|
|
1643
|
+
return objectType({
|
|
1644
|
+
name,
|
|
1645
|
+
definition(t) {
|
|
1646
|
+
t.field("data", {
|
|
1647
|
+
type: entityName,
|
|
1648
|
+
resolve: prop("value")
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
};
|
|
1655
|
+
const responseCollection = ({ strapi: strapi2 }) => {
|
|
1656
|
+
const { naming: naming2 } = strapi2.plugin("graphql").service("utils");
|
|
1657
|
+
const { RESPONSE_COLLECTION_META_TYPE_NAME: RESPONSE_COLLECTION_META_TYPE_NAME2 } = strapi2.plugin("graphql").service("constants");
|
|
1658
|
+
return {
|
|
1659
|
+
/**
|
|
1660
|
+
* Build a type definition for a content API collection response for a given content type
|
|
1661
|
+
* @param {Schema.ContentType} contentType The content type which will be used to build its content API response definition
|
|
1662
|
+
* @return {NexusObjectTypeDef}
|
|
1663
|
+
*/
|
|
1664
|
+
buildResponseCollectionDefinition(contentType2) {
|
|
1665
|
+
const name = naming2.getEntityResponseCollectionName(contentType2);
|
|
1666
|
+
const entityName = naming2.getEntityName(contentType2);
|
|
1667
|
+
return objectType({
|
|
1668
|
+
name,
|
|
1669
|
+
definition(t) {
|
|
1670
|
+
t.nonNull.list.field("data", {
|
|
1671
|
+
type: nonNull(entityName),
|
|
1672
|
+
resolve: pipe(prop("nodes"), defaultTo([]))
|
|
1673
|
+
});
|
|
1674
|
+
t.nonNull.field("meta", {
|
|
1675
|
+
type: RESPONSE_COLLECTION_META_TYPE_NAME2,
|
|
1676
|
+
// Pass down the args stored in the source object
|
|
1677
|
+
resolve: prop("info")
|
|
1678
|
+
});
|
|
1679
|
+
}
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
};
|
|
1684
|
+
const relationResponseCollection = ({ strapi: strapi2 }) => {
|
|
1685
|
+
const { naming: naming2 } = strapi2.plugin("graphql").service("utils");
|
|
1686
|
+
return {
|
|
1687
|
+
/**
|
|
1688
|
+
* Build a type definition for a content API relation's collection response for a given content type
|
|
1689
|
+
*/
|
|
1690
|
+
buildRelationResponseCollectionDefinition(contentType2) {
|
|
1691
|
+
const name = naming2.getRelationResponseCollectionName(contentType2);
|
|
1692
|
+
const entityName = naming2.getEntityName(contentType2);
|
|
1693
|
+
return objectType({
|
|
1694
|
+
name,
|
|
1695
|
+
definition(t) {
|
|
1696
|
+
t.nonNull.list.field("data", {
|
|
1697
|
+
type: nonNull(entityName),
|
|
1698
|
+
resolve: pipe(prop("nodes"), defaultTo([]))
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
};
|
|
1704
|
+
};
|
|
1705
|
+
const createCollectionTypeQueriesBuilder = ({ strapi: strapi2 }) => {
|
|
1706
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
1707
|
+
const { naming: naming2 } = getService("utils");
|
|
1708
|
+
const { transformArgs, getContentTypeArgs } = getService("builders").utils;
|
|
1709
|
+
const { toEntityResponse, toEntityResponseCollection } = getService("format").returnTypes;
|
|
1710
|
+
const {
|
|
1711
|
+
getFindOneQueryName,
|
|
1712
|
+
getEntityResponseName,
|
|
1713
|
+
getFindQueryName,
|
|
1714
|
+
getEntityResponseCollectionName
|
|
1715
|
+
} = naming2;
|
|
1716
|
+
const buildCollectionTypeQueries = (contentType2) => {
|
|
1717
|
+
const findOneQueryName = `Query.${getFindOneQueryName(contentType2)}`;
|
|
1718
|
+
const findQueryName = `Query.${getFindQueryName(contentType2)}`;
|
|
1719
|
+
const extension = getService("extension");
|
|
1720
|
+
const registerAuthConfig = (action, auth) => {
|
|
1721
|
+
return extension.use({ resolversConfig: { [action]: { auth } } });
|
|
1722
|
+
};
|
|
1723
|
+
const isActionEnabled = (action) => {
|
|
1724
|
+
return extension.shadowCRUD(contentType2.uid).isActionEnabled(action);
|
|
1725
|
+
};
|
|
1726
|
+
const isFindOneEnabled = isActionEnabled("findOne");
|
|
1727
|
+
const isFindEnabled = isActionEnabled("find");
|
|
1728
|
+
if (isFindOneEnabled) {
|
|
1729
|
+
registerAuthConfig(findOneQueryName, { scope: [`${contentType2.uid}.findOne`] });
|
|
1730
|
+
}
|
|
1731
|
+
if (isFindEnabled) {
|
|
1732
|
+
registerAuthConfig(findQueryName, { scope: [`${contentType2.uid}.find`] });
|
|
1733
|
+
}
|
|
1734
|
+
return extendType({
|
|
1735
|
+
type: "Query",
|
|
1736
|
+
definition(t) {
|
|
1737
|
+
if (isFindOneEnabled) {
|
|
1738
|
+
addFindOneQuery(t, contentType2);
|
|
1739
|
+
}
|
|
1740
|
+
if (isFindEnabled) {
|
|
1741
|
+
addFindQuery(t, contentType2);
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
});
|
|
1745
|
+
};
|
|
1746
|
+
const addFindOneQuery = (t, contentType2) => {
|
|
1747
|
+
const { uid } = contentType2;
|
|
1748
|
+
const findOneQueryName = getFindOneQueryName(contentType2);
|
|
1749
|
+
const responseTypeName = getEntityResponseName(contentType2);
|
|
1750
|
+
t.field(findOneQueryName, {
|
|
1751
|
+
type: responseTypeName,
|
|
1752
|
+
args: getContentTypeArgs(contentType2, { multiple: false }),
|
|
1753
|
+
async resolve(parent, args2, ctx) {
|
|
1754
|
+
const transformedArgs = transformArgs(args2, { contentType: contentType2 });
|
|
1755
|
+
const { findOne } = getService("builders").get("content-api").buildQueriesResolvers({ contentType: contentType2 });
|
|
1756
|
+
const value = findOne(parent, transformedArgs, ctx);
|
|
1757
|
+
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
1758
|
+
}
|
|
1759
|
+
});
|
|
1760
|
+
};
|
|
1761
|
+
const addFindQuery = (t, contentType2) => {
|
|
1762
|
+
const { uid } = contentType2;
|
|
1763
|
+
const findQueryName = getFindQueryName(contentType2);
|
|
1764
|
+
const responseCollectionTypeName = getEntityResponseCollectionName(contentType2);
|
|
1765
|
+
t.field(findQueryName, {
|
|
1766
|
+
type: responseCollectionTypeName,
|
|
1767
|
+
args: getContentTypeArgs(contentType2),
|
|
1768
|
+
async resolve(parent, args2, ctx) {
|
|
1769
|
+
const transformedArgs = transformArgs(args2, { contentType: contentType2, usePagination: true });
|
|
1770
|
+
const { find } = getService("builders").get("content-api").buildQueriesResolvers({ contentType: contentType2 });
|
|
1771
|
+
const nodes = await find(parent, transformedArgs, ctx);
|
|
1772
|
+
return toEntityResponseCollection(nodes, { args: transformedArgs, resourceUID: uid });
|
|
1773
|
+
}
|
|
1774
|
+
});
|
|
1775
|
+
};
|
|
1776
|
+
return { buildCollectionTypeQueries };
|
|
1777
|
+
};
|
|
1778
|
+
const createSingleTypeQueriesBuilder = ({ strapi: strapi2 }) => {
|
|
1779
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
1780
|
+
const { naming: naming2 } = getService("utils");
|
|
1781
|
+
const { transformArgs, getContentTypeArgs } = getService("builders").utils;
|
|
1782
|
+
const { toEntityResponse } = getService("format").returnTypes;
|
|
1783
|
+
const { getFindOneQueryName, getEntityResponseName } = naming2;
|
|
1784
|
+
const buildSingleTypeQueries = (contentType2) => {
|
|
1785
|
+
const findQueryName = `Query.${getFindOneQueryName(contentType2)}`;
|
|
1786
|
+
const extension = getService("extension");
|
|
1787
|
+
const registerAuthConfig = (action, auth) => {
|
|
1788
|
+
return extension.use({ resolversConfig: { [action]: { auth } } });
|
|
1789
|
+
};
|
|
1790
|
+
const isActionEnabled = (action) => {
|
|
1791
|
+
return extension.shadowCRUD(contentType2.uid).isActionEnabled(action);
|
|
1792
|
+
};
|
|
1793
|
+
const isFindEnabled = isActionEnabled("find");
|
|
1794
|
+
if (isFindEnabled) {
|
|
1795
|
+
registerAuthConfig(findQueryName, { scope: [`${contentType2.uid}.find`] });
|
|
1796
|
+
}
|
|
1797
|
+
return extendType({
|
|
1798
|
+
type: "Query",
|
|
1799
|
+
definition(t) {
|
|
1800
|
+
if (isFindEnabled) {
|
|
1801
|
+
addFindQuery(t, contentType2);
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
});
|
|
1805
|
+
};
|
|
1806
|
+
const addFindQuery = (t, contentType2) => {
|
|
1807
|
+
const { uid } = contentType2;
|
|
1808
|
+
const findQueryName = getFindOneQueryName(contentType2);
|
|
1809
|
+
const responseTypeName = getEntityResponseName(contentType2);
|
|
1810
|
+
t.field(findQueryName, {
|
|
1811
|
+
type: responseTypeName,
|
|
1812
|
+
args: getContentTypeArgs(contentType2),
|
|
1813
|
+
async resolve(parent, args2, ctx) {
|
|
1814
|
+
const transformedArgs = transformArgs(args2, { contentType: contentType2 });
|
|
1815
|
+
const queriesResolvers2 = getService("builders").get("content-api").buildQueriesResolvers({ contentType: contentType2 });
|
|
1816
|
+
const value = queriesResolvers2.find(parent, transformedArgs, ctx);
|
|
1817
|
+
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
1818
|
+
}
|
|
1819
|
+
});
|
|
1820
|
+
};
|
|
1821
|
+
return { buildSingleTypeQueries };
|
|
1822
|
+
};
|
|
1823
|
+
const queries = (context) => ({
|
|
1824
|
+
...createCollectionTypeQueriesBuilder(context),
|
|
1825
|
+
...createSingleTypeQueriesBuilder(context)
|
|
1826
|
+
});
|
|
1827
|
+
const createCollectionTypeMutationsBuilder = ({ strapi: strapi2 }) => {
|
|
1828
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
1829
|
+
const { naming: naming2 } = getService("utils");
|
|
1830
|
+
const { transformArgs } = getService("builders").utils;
|
|
1831
|
+
const { toEntityResponse } = getService("format").returnTypes;
|
|
1832
|
+
const {
|
|
1833
|
+
getCreateMutationTypeName,
|
|
1834
|
+
getUpdateMutationTypeName,
|
|
1835
|
+
getDeleteMutationTypeName,
|
|
1836
|
+
getEntityResponseName,
|
|
1837
|
+
getContentTypeInputName
|
|
1838
|
+
} = naming2;
|
|
1839
|
+
const addCreateMutation = (t, contentType2) => {
|
|
1840
|
+
const { uid } = contentType2;
|
|
1841
|
+
const createMutationName = getCreateMutationTypeName(contentType2);
|
|
1842
|
+
const responseTypeName = getEntityResponseName(contentType2);
|
|
1843
|
+
t.field(createMutationName, {
|
|
1844
|
+
type: responseTypeName,
|
|
1845
|
+
args: {
|
|
1846
|
+
// Create payload
|
|
1847
|
+
data: nonNull(getContentTypeInputName(contentType2))
|
|
1848
|
+
},
|
|
1849
|
+
async resolve(parent, args2, context) {
|
|
1850
|
+
const { auth } = context.state;
|
|
1851
|
+
const transformedArgs = transformArgs(args2, { contentType: contentType2 });
|
|
1852
|
+
const sanitizedInputData = await sanitize.contentAPI.input(
|
|
1853
|
+
transformedArgs.data,
|
|
1854
|
+
contentType2,
|
|
1855
|
+
{ auth }
|
|
1856
|
+
);
|
|
1857
|
+
Object.assign(transformedArgs, { data: sanitizedInputData });
|
|
1858
|
+
const { create } = getService("builders").get("content-api").buildMutationsResolvers({ contentType: contentType2 });
|
|
1859
|
+
const value = await create(parent, transformedArgs);
|
|
1860
|
+
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
1861
|
+
}
|
|
1862
|
+
});
|
|
1863
|
+
};
|
|
1864
|
+
const addUpdateMutation = (t, contentType2) => {
|
|
1865
|
+
const { uid } = contentType2;
|
|
1866
|
+
const updateMutationName = getUpdateMutationTypeName(contentType2);
|
|
1867
|
+
const responseTypeName = getEntityResponseName(contentType2);
|
|
1868
|
+
t.field(updateMutationName, {
|
|
1869
|
+
type: responseTypeName,
|
|
1870
|
+
args: {
|
|
1871
|
+
// Query args
|
|
1872
|
+
id: nonNull("ID"),
|
|
1873
|
+
// todo[v4]: Don't allow to filter using every unique attributes for now
|
|
1874
|
+
// ...uniqueAttributes,
|
|
1875
|
+
// Update payload
|
|
1876
|
+
data: nonNull(getContentTypeInputName(contentType2))
|
|
1877
|
+
},
|
|
1878
|
+
async resolve(parent, args2, context) {
|
|
1879
|
+
const { auth } = context.state;
|
|
1880
|
+
const transformedArgs = transformArgs(args2, { contentType: contentType2 });
|
|
1881
|
+
const sanitizedInputData = await sanitize.contentAPI.input(
|
|
1882
|
+
transformedArgs.data,
|
|
1883
|
+
contentType2,
|
|
1884
|
+
{ auth }
|
|
1885
|
+
);
|
|
1886
|
+
Object.assign(transformedArgs, { data: sanitizedInputData });
|
|
1887
|
+
const { update } = getService("builders").get("content-api").buildMutationsResolvers({ contentType: contentType2 });
|
|
1888
|
+
const value = await update(parent, transformedArgs);
|
|
1889
|
+
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
1890
|
+
}
|
|
1891
|
+
});
|
|
1892
|
+
};
|
|
1893
|
+
const addDeleteMutation = (t, contentType2) => {
|
|
1894
|
+
const { uid } = contentType2;
|
|
1895
|
+
const deleteMutationName = getDeleteMutationTypeName(contentType2);
|
|
1896
|
+
const responseTypeName = getEntityResponseName(contentType2);
|
|
1897
|
+
t.field(deleteMutationName, {
|
|
1898
|
+
type: responseTypeName,
|
|
1899
|
+
args: {
|
|
1900
|
+
// Query args
|
|
1901
|
+
id: nonNull("ID")
|
|
1902
|
+
// todo[v4]: Don't allow to filter using every unique attributes for now
|
|
1903
|
+
// ...uniqueAttributes,
|
|
1904
|
+
},
|
|
1905
|
+
async resolve(parent, args2, ctx) {
|
|
1906
|
+
const transformedArgs = transformArgs(args2, { contentType: contentType2 });
|
|
1907
|
+
const { delete: deleteResolver } = getService("builders").get("content-api").buildMutationsResolvers({ contentType: contentType2 });
|
|
1908
|
+
const value = await deleteResolver(parent, args2, ctx);
|
|
1909
|
+
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
1910
|
+
}
|
|
1911
|
+
});
|
|
1912
|
+
};
|
|
1913
|
+
return {
|
|
1914
|
+
buildCollectionTypeMutations(contentType2) {
|
|
1915
|
+
const createMutationName = `Mutation.${getCreateMutationTypeName(contentType2)}`;
|
|
1916
|
+
const updateMutationName = `Mutation.${getUpdateMutationTypeName(contentType2)}`;
|
|
1917
|
+
const deleteMutationName = `Mutation.${getDeleteMutationTypeName(contentType2)}`;
|
|
1918
|
+
const extension = getService("extension");
|
|
1919
|
+
const registerAuthConfig = (action, auth) => {
|
|
1920
|
+
return extension.use({ resolversConfig: { [action]: { auth } } });
|
|
1921
|
+
};
|
|
1922
|
+
const isActionEnabled = (action) => {
|
|
1923
|
+
return extension.shadowCRUD(contentType2.uid).isActionEnabled(action);
|
|
1924
|
+
};
|
|
1925
|
+
const isCreateEnabled = isActionEnabled("create");
|
|
1926
|
+
const isUpdateEnabled = isActionEnabled("update");
|
|
1927
|
+
const isDeleteEnabled = isActionEnabled("delete");
|
|
1928
|
+
if (isCreateEnabled) {
|
|
1929
|
+
registerAuthConfig(createMutationName, { scope: [`${contentType2.uid}.create`] });
|
|
1930
|
+
}
|
|
1931
|
+
if (isUpdateEnabled) {
|
|
1932
|
+
registerAuthConfig(updateMutationName, { scope: [`${contentType2.uid}.update`] });
|
|
1933
|
+
}
|
|
1934
|
+
if (isDeleteEnabled) {
|
|
1935
|
+
registerAuthConfig(deleteMutationName, { scope: [`${contentType2.uid}.delete`] });
|
|
1936
|
+
}
|
|
1937
|
+
return extendType({
|
|
1938
|
+
type: "Mutation",
|
|
1939
|
+
definition(t) {
|
|
1940
|
+
if (isCreateEnabled) {
|
|
1941
|
+
addCreateMutation(t, contentType2);
|
|
1942
|
+
}
|
|
1943
|
+
if (isUpdateEnabled) {
|
|
1944
|
+
addUpdateMutation(t, contentType2);
|
|
1945
|
+
}
|
|
1946
|
+
if (isDeleteEnabled) {
|
|
1947
|
+
addDeleteMutation(t, contentType2);
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
};
|
|
1954
|
+
const { NotFoundError } = errors;
|
|
1955
|
+
const createSingleTypeMutationsBuilder = ({ strapi: strapi2 }) => {
|
|
1956
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
1957
|
+
const { naming: naming2 } = getService("utils");
|
|
1958
|
+
const { transformArgs } = getService("builders").utils;
|
|
1959
|
+
const { toEntityResponse } = getService("format").returnTypes;
|
|
1960
|
+
const {
|
|
1961
|
+
getUpdateMutationTypeName,
|
|
1962
|
+
getEntityResponseName,
|
|
1963
|
+
getContentTypeInputName,
|
|
1964
|
+
getDeleteMutationTypeName
|
|
1965
|
+
} = naming2;
|
|
1966
|
+
const addUpdateMutation = (t, contentType2) => {
|
|
1967
|
+
const { uid } = contentType2;
|
|
1968
|
+
const updateMutationName = getUpdateMutationTypeName(contentType2);
|
|
1969
|
+
const responseTypeName = getEntityResponseName(contentType2);
|
|
1970
|
+
t.field(updateMutationName, {
|
|
1971
|
+
type: responseTypeName,
|
|
1972
|
+
args: {
|
|
1973
|
+
// Update payload
|
|
1974
|
+
data: nonNull(getContentTypeInputName(contentType2))
|
|
1975
|
+
},
|
|
1976
|
+
async resolve(parent, args2, context) {
|
|
1977
|
+
const { auth } = context.state;
|
|
1978
|
+
const transformedArgs = transformArgs(args2, { contentType: contentType2 });
|
|
1979
|
+
const sanitizedInputData = await sanitize.contentAPI.input(
|
|
1980
|
+
transformedArgs.data,
|
|
1981
|
+
contentType2,
|
|
1982
|
+
{ auth }
|
|
1983
|
+
);
|
|
1984
|
+
Object.assign(transformedArgs, { data: sanitizedInputData });
|
|
1985
|
+
const { create, update } = getService("builders").get("content-api").buildMutationsResolvers({ contentType: contentType2 });
|
|
1986
|
+
await validate.contentAPI.query(omit(["data", "files"], transformedArgs), contentType2, {
|
|
1987
|
+
auth
|
|
1988
|
+
});
|
|
1989
|
+
const sanitizedQuery = await sanitize.contentAPI.query(
|
|
1990
|
+
omit(["data", "files"], transformedArgs),
|
|
1991
|
+
contentType2,
|
|
1992
|
+
{
|
|
1993
|
+
auth
|
|
1994
|
+
}
|
|
1995
|
+
);
|
|
1996
|
+
const entity2 = await strapi2.entityService.findMany(uid, sanitizedQuery);
|
|
1997
|
+
const value = isNil(entity2) ? create(parent, transformedArgs) : update(uid, { id: entity2.id, data: transformedArgs.data });
|
|
1998
|
+
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
1999
|
+
}
|
|
2000
|
+
});
|
|
2001
|
+
};
|
|
2002
|
+
const addDeleteMutation = (t, contentType2) => {
|
|
2003
|
+
const { uid } = contentType2;
|
|
2004
|
+
const deleteMutationName = getDeleteMutationTypeName(contentType2);
|
|
2005
|
+
const responseTypeName = getEntityResponseName(contentType2);
|
|
2006
|
+
t.field(deleteMutationName, {
|
|
2007
|
+
type: responseTypeName,
|
|
2008
|
+
args: {},
|
|
2009
|
+
async resolve(parent, args2, ctx) {
|
|
2010
|
+
const transformedArgs = transformArgs(args2, { contentType: contentType2 });
|
|
2011
|
+
const { delete: deleteResolver } = getService("builders").get("content-api").buildMutationsResolvers({ contentType: contentType2 });
|
|
2012
|
+
await validate.contentAPI.query(transformedArgs, contentType2, { auth: ctx?.state?.auth });
|
|
2013
|
+
const sanitizedQuery = await sanitize.contentAPI.query(transformedArgs, contentType2, {
|
|
2014
|
+
auth: ctx?.state?.auth
|
|
2015
|
+
});
|
|
2016
|
+
const entity2 = await strapi2.entityService.findMany(uid, sanitizedQuery);
|
|
2017
|
+
if (!entity2) {
|
|
2018
|
+
throw new NotFoundError("Entity not found");
|
|
2019
|
+
}
|
|
2020
|
+
const value = await deleteResolver(parent, { id: entity2.id, params: transformedArgs });
|
|
2021
|
+
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
2022
|
+
}
|
|
2023
|
+
});
|
|
2024
|
+
};
|
|
2025
|
+
return {
|
|
2026
|
+
buildSingleTypeMutations(contentType2) {
|
|
2027
|
+
const updateMutationName = `Mutation.${getUpdateMutationTypeName(contentType2)}`;
|
|
2028
|
+
const deleteMutationName = `Mutation.${getDeleteMutationTypeName(contentType2)}`;
|
|
2029
|
+
const extension = getService("extension");
|
|
2030
|
+
const registerAuthConfig = (action, auth) => {
|
|
2031
|
+
return extension.use({ resolversConfig: { [action]: { auth } } });
|
|
2032
|
+
};
|
|
2033
|
+
const isActionEnabled = (action) => {
|
|
2034
|
+
return extension.shadowCRUD(contentType2.uid).isActionEnabled(action);
|
|
2035
|
+
};
|
|
2036
|
+
const isUpdateEnabled = isActionEnabled("update");
|
|
2037
|
+
const isDeleteEnabled = isActionEnabled("delete");
|
|
2038
|
+
if (isUpdateEnabled) {
|
|
2039
|
+
registerAuthConfig(updateMutationName, { scope: [`${contentType2.uid}.update`] });
|
|
2040
|
+
}
|
|
2041
|
+
if (isDeleteEnabled) {
|
|
2042
|
+
registerAuthConfig(deleteMutationName, { scope: [`${contentType2.uid}.delete`] });
|
|
2043
|
+
}
|
|
2044
|
+
return extendType({
|
|
2045
|
+
type: "Mutation",
|
|
2046
|
+
definition(t) {
|
|
2047
|
+
if (isUpdateEnabled) {
|
|
2048
|
+
addUpdateMutation(t, contentType2);
|
|
2049
|
+
}
|
|
2050
|
+
if (isDeleteEnabled) {
|
|
2051
|
+
addDeleteMutation(t, contentType2);
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
});
|
|
2055
|
+
}
|
|
2056
|
+
};
|
|
2057
|
+
};
|
|
2058
|
+
const mutations = (context) => ({
|
|
2059
|
+
...createCollectionTypeMutationsBuilder(context),
|
|
2060
|
+
...createSingleTypeMutationsBuilder(context)
|
|
2061
|
+
});
|
|
2062
|
+
const contentType = ({ strapi: strapi2 }) => {
|
|
2063
|
+
const rootLevelOperators = () => {
|
|
2064
|
+
const { operators: operators2 } = strapi2.plugin("graphql").service("builders").filters;
|
|
2065
|
+
return [operators2.and, operators2.or, operators2.not];
|
|
2066
|
+
};
|
|
2067
|
+
const addScalarAttribute = (builder, attributeName, attribute) => {
|
|
2068
|
+
const { naming: naming2, mappers: mappers2 } = strapi2.plugin("graphql").service("utils");
|
|
2069
|
+
const gqlType = mappers2.strapiScalarToGraphQLScalar(attribute.type);
|
|
2070
|
+
builder.field(attributeName, { type: naming2.getScalarFilterInputTypeName(gqlType) });
|
|
2071
|
+
};
|
|
2072
|
+
const addRelationalAttribute = (builder, attributeName, attribute) => {
|
|
2073
|
+
const utils2 = strapi2.plugin("graphql").service("utils");
|
|
2074
|
+
const extension = strapi2.plugin("graphql").service("extension");
|
|
2075
|
+
const { getFiltersInputTypeName } = utils2.naming;
|
|
2076
|
+
const { isMorphRelation } = utils2.attributes;
|
|
2077
|
+
const model = "target" in attribute && strapi2.getModel(attribute.target);
|
|
2078
|
+
if (!model || isMorphRelation(attribute))
|
|
2079
|
+
return;
|
|
2080
|
+
if (extension.shadowCRUD(model.uid).isDisabled())
|
|
2081
|
+
return;
|
|
2082
|
+
builder.field(attributeName, { type: getFiltersInputTypeName(model) });
|
|
2083
|
+
};
|
|
2084
|
+
const addComponentAttribute = (builder, attributeName, attribute) => {
|
|
2085
|
+
const utils2 = strapi2.plugin("graphql").service("utils");
|
|
2086
|
+
const extension = strapi2.plugin("graphql").service("extension");
|
|
2087
|
+
const { getFiltersInputTypeName } = utils2.naming;
|
|
2088
|
+
const component = strapi2.getModel(attribute.component);
|
|
2089
|
+
if (!component)
|
|
2090
|
+
return;
|
|
2091
|
+
if (extension.shadowCRUD(component.uid).isDisabled())
|
|
2092
|
+
return;
|
|
2093
|
+
builder.field(attributeName, { type: getFiltersInputTypeName(component) });
|
|
2094
|
+
};
|
|
2095
|
+
const buildContentTypeFilters = (contentType2) => {
|
|
2096
|
+
const utils2 = strapi2.plugin("graphql").service("utils");
|
|
2097
|
+
const extension = strapi2.plugin("graphql").service("extension");
|
|
2098
|
+
const { getFiltersInputTypeName, getScalarFilterInputTypeName } = utils2.naming;
|
|
2099
|
+
const { isStrapiScalar, isRelation, isComponent } = utils2.attributes;
|
|
2100
|
+
const { attributes: attributes2 } = contentType2;
|
|
2101
|
+
const filtersTypeName = getFiltersInputTypeName(contentType2);
|
|
2102
|
+
return inputObjectType({
|
|
2103
|
+
name: filtersTypeName,
|
|
2104
|
+
definition(t) {
|
|
2105
|
+
const validAttributes = Object.entries(attributes2).filter(
|
|
2106
|
+
([attributeName]) => extension.shadowCRUD(contentType2.uid).field(attributeName).hasFiltersEnabeld()
|
|
2107
|
+
);
|
|
2108
|
+
const isIDFilterEnabled = extension.shadowCRUD(contentType2.uid).field("id").hasFiltersEnabeld();
|
|
2109
|
+
if (contentType2.kind === "collectionType" && isIDFilterEnabled) {
|
|
2110
|
+
t.field("id", { type: getScalarFilterInputTypeName("ID") });
|
|
2111
|
+
}
|
|
2112
|
+
for (const [attributeName, attribute] of validAttributes) {
|
|
2113
|
+
if (isStrapiScalar(attribute)) {
|
|
2114
|
+
addScalarAttribute(t, attributeName, attribute);
|
|
2115
|
+
} else if (isRelation(attribute)) {
|
|
2116
|
+
addRelationalAttribute(t, attributeName, attribute);
|
|
2117
|
+
} else if (isComponent(attribute)) {
|
|
2118
|
+
addComponentAttribute(t, attributeName, attribute);
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
for (const operator of rootLevelOperators()) {
|
|
2122
|
+
operator.add(t, filtersTypeName);
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
});
|
|
2126
|
+
};
|
|
2127
|
+
return {
|
|
2128
|
+
buildContentTypeFilters
|
|
2129
|
+
};
|
|
2130
|
+
};
|
|
2131
|
+
const filters = (context) => ({
|
|
2132
|
+
...contentType(context)
|
|
2133
|
+
});
|
|
2134
|
+
const { isWritableAttribute } = contentTypes;
|
|
2135
|
+
const inputs = ({ strapi: strapi2 }) => {
|
|
2136
|
+
const { naming: naming2, mappers: mappers2, attributes: attributes2 } = strapi2.plugin("graphql").service("utils");
|
|
2137
|
+
const extension = strapi2.plugin("graphql").service("extension");
|
|
2138
|
+
const { getComponentInputName, getContentTypeInputName, getEnumName, getDynamicZoneInputName } = naming2;
|
|
2139
|
+
const {
|
|
2140
|
+
isStrapiScalar,
|
|
2141
|
+
isRelation,
|
|
2142
|
+
isMorphRelation,
|
|
2143
|
+
isMedia,
|
|
2144
|
+
isEnumeration,
|
|
2145
|
+
isComponent,
|
|
2146
|
+
isDynamicZone
|
|
2147
|
+
} = attributes2;
|
|
2148
|
+
return {
|
|
2149
|
+
buildInputType(contentType2) {
|
|
2150
|
+
const { attributes: attributes22, modelType } = contentType2;
|
|
2151
|
+
const name = (modelType === "component" ? getComponentInputName : getContentTypeInputName).call(null, contentType2);
|
|
2152
|
+
return inputObjectType({
|
|
2153
|
+
name,
|
|
2154
|
+
definition(t) {
|
|
2155
|
+
const isFieldEnabled = (fieldName) => {
|
|
2156
|
+
return extension.shadowCRUD(contentType2.uid).field(fieldName).hasInputEnabled();
|
|
2157
|
+
};
|
|
2158
|
+
const validAttributes = Object.entries(attributes22).filter(([attributeName]) => {
|
|
2159
|
+
return isWritableAttribute(contentType2, attributeName) && isFieldEnabled(attributeName);
|
|
2160
|
+
});
|
|
2161
|
+
if (modelType === "component" && isFieldEnabled("id")) {
|
|
2162
|
+
t.id("id");
|
|
2163
|
+
}
|
|
2164
|
+
validAttributes.forEach(([attributeName, attribute]) => {
|
|
2165
|
+
if (isEnumeration(attribute)) {
|
|
2166
|
+
const enumTypeName = getEnumName(contentType2, attributeName);
|
|
2167
|
+
t.field(attributeName, { type: enumTypeName });
|
|
2168
|
+
} else if (isStrapiScalar(attribute)) {
|
|
2169
|
+
const gqlScalar = mappers2.strapiScalarToGraphQLScalar(attribute.type);
|
|
2170
|
+
t.field(attributeName, { type: gqlScalar });
|
|
2171
|
+
} else if (isMedia(attribute)) {
|
|
2172
|
+
const isMultiple = attribute.multiple === true;
|
|
2173
|
+
if (extension.shadowCRUD("plugin::upload.file").isDisabled()) {
|
|
2174
|
+
return;
|
|
2175
|
+
}
|
|
2176
|
+
if (isMultiple) {
|
|
2177
|
+
t.list.id(attributeName);
|
|
2178
|
+
} else {
|
|
2179
|
+
t.id(attributeName);
|
|
2180
|
+
}
|
|
2181
|
+
} else if (isRelation(attribute) && !isMorphRelation(attribute)) {
|
|
2182
|
+
if (extension.shadowCRUD(attribute.target).isDisabled()) {
|
|
2183
|
+
return;
|
|
2184
|
+
}
|
|
2185
|
+
const isToManyRelation = attribute.relation.endsWith("Many");
|
|
2186
|
+
if (isToManyRelation) {
|
|
2187
|
+
t.list.id(attributeName);
|
|
2188
|
+
} else {
|
|
2189
|
+
t.id(attributeName);
|
|
2190
|
+
}
|
|
2191
|
+
} else if (isComponent(attribute)) {
|
|
2192
|
+
const isRepeatable = attribute.repeatable === true;
|
|
2193
|
+
const component = strapi2.components[attribute.component];
|
|
2194
|
+
const componentInputType = getComponentInputName(component);
|
|
2195
|
+
if (isRepeatable) {
|
|
2196
|
+
t.list.field(attributeName, { type: componentInputType });
|
|
2197
|
+
} else {
|
|
2198
|
+
t.field(attributeName, { type: componentInputType });
|
|
2199
|
+
}
|
|
2200
|
+
} else if (isDynamicZone(attribute)) {
|
|
2201
|
+
const dzInputName = getDynamicZoneInputName(contentType2, attributeName);
|
|
2202
|
+
t.list.field(attributeName, { type: nonNull(dzInputName) });
|
|
2203
|
+
}
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
};
|
|
2209
|
+
};
|
|
2210
|
+
const genericMorph = ({ strapi: strapi2, registry }) => {
|
|
2211
|
+
const { naming: naming2 } = strapi2.plugin("graphql").service("utils");
|
|
2212
|
+
const { KINDS: KINDS2, GENERIC_MORPH_TYPENAME: GENERIC_MORPH_TYPENAME2 } = strapi2.plugin("graphql").service("constants");
|
|
2213
|
+
return {
|
|
2214
|
+
buildGenericMorphDefinition() {
|
|
2215
|
+
return unionType({
|
|
2216
|
+
name: GENERIC_MORPH_TYPENAME2,
|
|
2217
|
+
resolveType(obj) {
|
|
2218
|
+
const contentType2 = strapi2.getModel(obj.__type);
|
|
2219
|
+
if (!contentType2) {
|
|
2220
|
+
return null;
|
|
2221
|
+
}
|
|
2222
|
+
if (contentType2.modelType === "component") {
|
|
2223
|
+
return naming2.getComponentName(contentType2);
|
|
2224
|
+
}
|
|
2225
|
+
return naming2.getTypeName(contentType2);
|
|
2226
|
+
},
|
|
2227
|
+
definition(t) {
|
|
2228
|
+
const members = registry.where(({ config: config2 }) => [KINDS2.type, KINDS2.component].includes(config2.kind)).map(prop("name"));
|
|
2229
|
+
t.members(...members);
|
|
2230
|
+
}
|
|
2231
|
+
});
|
|
2232
|
+
}
|
|
2233
|
+
};
|
|
2234
|
+
};
|
|
2235
|
+
const { ApplicationError } = errors;
|
|
2236
|
+
const associationResolvers = ({ strapi: strapi2 }) => {
|
|
2237
|
+
const { service: getGraphQLService } = strapi2.plugin("graphql");
|
|
2238
|
+
const { isMorphRelation, isMedia } = getGraphQLService("utils").attributes;
|
|
2239
|
+
const { transformArgs } = getGraphQLService("builders").utils;
|
|
2240
|
+
const { toEntityResponse, toEntityResponseCollection } = getGraphQLService("format").returnTypes;
|
|
2241
|
+
return {
|
|
2242
|
+
buildAssociationResolver({
|
|
2243
|
+
contentTypeUID,
|
|
2244
|
+
attributeName
|
|
2245
|
+
}) {
|
|
2246
|
+
const contentType2 = strapi2.getModel(contentTypeUID);
|
|
2247
|
+
const attribute = contentType2.attributes[attributeName];
|
|
2248
|
+
if (!attribute) {
|
|
2249
|
+
throw new ApplicationError(
|
|
2250
|
+
`Failed to build an association resolver for ${contentTypeUID}::${attributeName}`
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
const isMediaAttribute = isMedia(attribute);
|
|
2254
|
+
const isMorphAttribute = isMorphRelation(attribute);
|
|
2255
|
+
const targetUID = isMediaAttribute ? "plugin::upload.file" : attribute.target;
|
|
2256
|
+
const isToMany = isMediaAttribute ? attribute.multiple : attribute.relation.endsWith("Many");
|
|
2257
|
+
const targetContentType = strapi2.getModel(targetUID);
|
|
2258
|
+
return async (parent, args2 = {}, context = {}) => {
|
|
2259
|
+
const { auth } = context.state;
|
|
2260
|
+
const transformedArgs = transformArgs(args2, {
|
|
2261
|
+
contentType: targetContentType,
|
|
2262
|
+
usePagination: true
|
|
2263
|
+
});
|
|
2264
|
+
await validate.contentAPI.query(transformedArgs, targetContentType, {
|
|
2265
|
+
auth
|
|
2266
|
+
});
|
|
2267
|
+
const sanitizedQuery = await sanitize.contentAPI.query(transformedArgs, targetContentType, {
|
|
2268
|
+
auth
|
|
2269
|
+
});
|
|
2270
|
+
const data = await strapi2.entityService.load(
|
|
2271
|
+
contentTypeUID,
|
|
2272
|
+
parent,
|
|
2273
|
+
attributeName,
|
|
2274
|
+
sanitizedQuery
|
|
2275
|
+
);
|
|
2276
|
+
const info = {
|
|
2277
|
+
args: sanitizedQuery,
|
|
2278
|
+
resourceUID: targetUID
|
|
2279
|
+
};
|
|
2280
|
+
if (isMorphAttribute) {
|
|
2281
|
+
const wrapData = (dataToWrap) => ({ [attributeName]: dataToWrap });
|
|
2282
|
+
const sanitizeData = (dataToSanitize) => {
|
|
2283
|
+
return sanitize.contentAPI.output(dataToSanitize, contentType2, { auth });
|
|
2284
|
+
};
|
|
2285
|
+
const unwrapData = get(attributeName);
|
|
2286
|
+
const sanitizeMorphAttribute = pipeAsync(wrapData, sanitizeData, unwrapData);
|
|
2287
|
+
return sanitizeMorphAttribute(data);
|
|
2288
|
+
}
|
|
2289
|
+
if (isToMany) {
|
|
2290
|
+
return toEntityResponseCollection(data, info);
|
|
2291
|
+
}
|
|
2292
|
+
return toEntityResponse(data, info);
|
|
2293
|
+
};
|
|
2294
|
+
}
|
|
2295
|
+
};
|
|
2296
|
+
};
|
|
2297
|
+
const queriesResolvers = ({ strapi: strapi2 }) => ({
|
|
2298
|
+
buildQueriesResolvers({ contentType: contentType2 }) {
|
|
2299
|
+
const { uid } = contentType2;
|
|
2300
|
+
return {
|
|
2301
|
+
async find(parent, args2, ctx) {
|
|
2302
|
+
await validate.contentAPI.query(args2, contentType2, {
|
|
2303
|
+
auth: ctx?.state?.auth
|
|
2304
|
+
});
|
|
2305
|
+
const sanitizedQuery = await sanitize.contentAPI.query(args2, contentType2, {
|
|
2306
|
+
auth: ctx?.state?.auth
|
|
2307
|
+
});
|
|
2308
|
+
return strapi2.entityService.findMany(uid, sanitizedQuery);
|
|
2309
|
+
},
|
|
2310
|
+
async findOne(parent, args2, ctx) {
|
|
2311
|
+
await validate.contentAPI.query(args2, contentType2, {
|
|
2312
|
+
auth: ctx?.state?.auth
|
|
2313
|
+
});
|
|
2314
|
+
const sanitizedQuery = await sanitize.contentAPI.query(args2, contentType2, {
|
|
2315
|
+
auth: ctx?.state?.auth
|
|
2316
|
+
});
|
|
2317
|
+
return strapi2.entityService.findOne(uid, args2.id, omit("id", sanitizedQuery));
|
|
2318
|
+
}
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
});
|
|
2322
|
+
const pickCreateArgs = pick(["params", "data", "files"]);
|
|
2323
|
+
const mutationsResolvers = ({ strapi: strapi2 }) => ({
|
|
2324
|
+
buildMutationsResolvers({ contentType: contentType2 }) {
|
|
2325
|
+
const { uid } = contentType2;
|
|
2326
|
+
return {
|
|
2327
|
+
async create(parent, args2) {
|
|
2328
|
+
const params = pickCreateArgs(args2);
|
|
2329
|
+
return strapi2.entityService.create(uid, params);
|
|
2330
|
+
},
|
|
2331
|
+
async update(parent, args2) {
|
|
2332
|
+
const { id, data } = args2;
|
|
2333
|
+
return strapi2.entityService.update(uid, id, { data });
|
|
2334
|
+
},
|
|
2335
|
+
async delete(parent, args2, ctx) {
|
|
2336
|
+
const { id, ...rest } = args2;
|
|
2337
|
+
await validate.contentAPI.query(rest, contentType2, {
|
|
2338
|
+
auth: ctx?.state?.auth
|
|
2339
|
+
});
|
|
2340
|
+
const sanitizedQuery = await sanitize.contentAPI.query(rest, contentType2, {
|
|
2341
|
+
auth: ctx?.state?.auth
|
|
2342
|
+
});
|
|
2343
|
+
return strapi2.entityService.delete(uid, id, sanitizedQuery);
|
|
2344
|
+
}
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
});
|
|
2348
|
+
const componentResolvers = ({ strapi: strapi2 }) => ({
|
|
2349
|
+
buildComponentResolver({
|
|
2350
|
+
contentTypeUID,
|
|
2351
|
+
attributeName
|
|
2352
|
+
}) {
|
|
2353
|
+
const { transformArgs } = strapi2.plugin("graphql").service("builders").utils;
|
|
2354
|
+
return async (parent, args2, ctx) => {
|
|
2355
|
+
const contentType2 = strapi2.getModel(contentTypeUID);
|
|
2356
|
+
const { component: componentName } = contentType2.attributes[attributeName];
|
|
2357
|
+
const component = strapi2.getModel(componentName);
|
|
2358
|
+
const transformedArgs = transformArgs(args2, { contentType: component, usePagination: true });
|
|
2359
|
+
await validate.contentAPI.query(transformedArgs, component, {
|
|
2360
|
+
auth: ctx?.state?.auth
|
|
2361
|
+
});
|
|
2362
|
+
const sanitizedQuery = await sanitize.contentAPI.query(transformedArgs, component, {
|
|
2363
|
+
auth: ctx?.state?.auth
|
|
2364
|
+
});
|
|
2365
|
+
return strapi2.entityService.load(contentTypeUID, parent, attributeName, sanitizedQuery);
|
|
2366
|
+
};
|
|
2367
|
+
}
|
|
2368
|
+
});
|
|
2369
|
+
const dynamicZoneResolvers = ({ strapi: strapi2 }) => ({
|
|
2370
|
+
buildDynamicZoneResolver({
|
|
2371
|
+
contentTypeUID,
|
|
2372
|
+
attributeName
|
|
2373
|
+
}) {
|
|
2374
|
+
return async (parent) => {
|
|
2375
|
+
return strapi2.entityService.load(contentTypeUID, parent, attributeName);
|
|
2376
|
+
};
|
|
2377
|
+
}
|
|
2378
|
+
});
|
|
2379
|
+
const resolvers = (context) => ({
|
|
2380
|
+
// Generics
|
|
2381
|
+
...associationResolvers(context),
|
|
2382
|
+
// Builders
|
|
2383
|
+
...mutationsResolvers(context),
|
|
2384
|
+
...queriesResolvers(context),
|
|
2385
|
+
...componentResolvers(context),
|
|
2386
|
+
...dynamicZoneResolvers(context)
|
|
2387
|
+
});
|
|
2388
|
+
const AND_FIELD_NAME = "and";
|
|
2389
|
+
const andOperator = () => ({
|
|
2390
|
+
fieldName: AND_FIELD_NAME,
|
|
2391
|
+
strapiOperator: "$and",
|
|
2392
|
+
add(t, type) {
|
|
2393
|
+
t.field(AND_FIELD_NAME, { type: list(type) });
|
|
2394
|
+
}
|
|
2395
|
+
});
|
|
2396
|
+
const OR_FIELD_NAME = "or";
|
|
2397
|
+
const orOperator = () => ({
|
|
2398
|
+
fieldName: OR_FIELD_NAME,
|
|
2399
|
+
strapiOperator: "$or",
|
|
2400
|
+
add(t, type) {
|
|
2401
|
+
t.field(OR_FIELD_NAME, { type: list(type) });
|
|
2402
|
+
}
|
|
2403
|
+
});
|
|
2404
|
+
const NOT_FIELD_NAME = "not";
|
|
2405
|
+
const notOperator = ({ strapi: strapi2 }) => ({
|
|
2406
|
+
fieldName: NOT_FIELD_NAME,
|
|
2407
|
+
strapiOperator: "$not",
|
|
2408
|
+
add(t, type) {
|
|
2409
|
+
const { naming: naming2, attributes: attributes2 } = strapi2.plugin("graphql").service("utils");
|
|
2410
|
+
if (attributes2.isGraphQLScalar({ type })) {
|
|
2411
|
+
t.field(NOT_FIELD_NAME, { type: naming2.getScalarFilterInputTypeName(type) });
|
|
2412
|
+
} else {
|
|
2413
|
+
t.field(NOT_FIELD_NAME, { type });
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
});
|
|
2417
|
+
const { ValidationError } = errors;
|
|
2418
|
+
const EQ_FIELD_NAME = "eq";
|
|
2419
|
+
const eqOperator = ({ strapi: strapi2 }) => ({
|
|
2420
|
+
fieldName: EQ_FIELD_NAME,
|
|
2421
|
+
strapiOperator: "$eq",
|
|
2422
|
+
add(t, type) {
|
|
2423
|
+
const { GRAPHQL_SCALARS: GRAPHQL_SCALARS2 } = strapi2.plugin("graphql").service("constants");
|
|
2424
|
+
if (!GRAPHQL_SCALARS2.includes(type)) {
|
|
2425
|
+
throw new ValidationError(
|
|
2426
|
+
`Can't use "${EQ_FIELD_NAME}" operator. "${type}" is not a valid scalar`
|
|
2427
|
+
);
|
|
2428
|
+
}
|
|
2429
|
+
t.field(EQ_FIELD_NAME, { type });
|
|
2430
|
+
}
|
|
2431
|
+
});
|
|
2432
|
+
const EQI_FIELD_NAME = "eqi";
|
|
2433
|
+
const eqiOperator = () => ({
|
|
2434
|
+
fieldName: EQI_FIELD_NAME,
|
|
2435
|
+
strapiOperator: "$eqi",
|
|
2436
|
+
add(t, type) {
|
|
2437
|
+
t.field(EQI_FIELD_NAME, { type });
|
|
2438
|
+
}
|
|
2439
|
+
});
|
|
2440
|
+
const NE_FIELD_NAME = "ne";
|
|
2441
|
+
const neOperator = () => ({
|
|
2442
|
+
fieldName: NE_FIELD_NAME,
|
|
2443
|
+
strapiOperator: "$ne",
|
|
2444
|
+
add(t, type) {
|
|
2445
|
+
t.field(NE_FIELD_NAME, { type });
|
|
2446
|
+
}
|
|
2447
|
+
});
|
|
2448
|
+
const NEI_FIELD_NAME = "nei";
|
|
2449
|
+
const neiOperator = () => ({
|
|
2450
|
+
fieldName: NEI_FIELD_NAME,
|
|
2451
|
+
strapiOperator: "$nei",
|
|
2452
|
+
add(t, type) {
|
|
2453
|
+
t.field(NEI_FIELD_NAME, { type });
|
|
2454
|
+
}
|
|
2455
|
+
});
|
|
2456
|
+
const STARTS_WITH_FIELD_NAME = "startsWith";
|
|
2457
|
+
const startsWithOperator = () => ({
|
|
2458
|
+
fieldName: STARTS_WITH_FIELD_NAME,
|
|
2459
|
+
strapiOperator: "$startsWith",
|
|
2460
|
+
add(t, type) {
|
|
2461
|
+
t.field(STARTS_WITH_FIELD_NAME, { type });
|
|
2462
|
+
}
|
|
2463
|
+
});
|
|
2464
|
+
const ENDS_WITH_FIELD_NAME = "endsWith";
|
|
2465
|
+
const endsWithOperator = () => ({
|
|
2466
|
+
fieldName: ENDS_WITH_FIELD_NAME,
|
|
2467
|
+
strapiOperator: "$endsWith",
|
|
2468
|
+
add(t, type) {
|
|
2469
|
+
t.field(ENDS_WITH_FIELD_NAME, { type });
|
|
2470
|
+
}
|
|
2471
|
+
});
|
|
2472
|
+
const CONTAINS_FIELD_NAME = "contains";
|
|
2473
|
+
const containsOperator = () => ({
|
|
2474
|
+
fieldName: CONTAINS_FIELD_NAME,
|
|
2475
|
+
strapiOperator: "$contains",
|
|
2476
|
+
add(t, type) {
|
|
2477
|
+
t.field(CONTAINS_FIELD_NAME, { type });
|
|
2478
|
+
}
|
|
2479
|
+
});
|
|
2480
|
+
const NOT_CONTAINS_FIELD_NAME = "notContains";
|
|
2481
|
+
const notContainsOperator = () => ({
|
|
2482
|
+
fieldName: NOT_CONTAINS_FIELD_NAME,
|
|
2483
|
+
strapiOperator: "$notContains",
|
|
2484
|
+
add(t, type) {
|
|
2485
|
+
t.field(NOT_CONTAINS_FIELD_NAME, { type });
|
|
2486
|
+
}
|
|
2487
|
+
});
|
|
2488
|
+
const CONTAINSI_FIELD_NAME = "containsi";
|
|
2489
|
+
const containsiOperator = () => ({
|
|
2490
|
+
fieldName: CONTAINSI_FIELD_NAME,
|
|
2491
|
+
strapiOperator: "$containsi",
|
|
2492
|
+
add(t, type) {
|
|
2493
|
+
t.field(CONTAINSI_FIELD_NAME, { type });
|
|
2494
|
+
}
|
|
2495
|
+
});
|
|
2496
|
+
const NOT_CONTAINSI_FIELD_NAME = "notContainsi";
|
|
2497
|
+
const notContainsiOperator = () => ({
|
|
2498
|
+
fieldName: NOT_CONTAINSI_FIELD_NAME,
|
|
2499
|
+
strapiOperator: "$notContainsi",
|
|
2500
|
+
add(t, type) {
|
|
2501
|
+
t.field(NOT_CONTAINSI_FIELD_NAME, { type });
|
|
2502
|
+
}
|
|
2503
|
+
});
|
|
2504
|
+
const GT_FIELD_NAME = "gt";
|
|
2505
|
+
const gtOperator = () => ({
|
|
2506
|
+
fieldName: GT_FIELD_NAME,
|
|
2507
|
+
strapiOperator: "$gt",
|
|
2508
|
+
add(t, type) {
|
|
2509
|
+
t.field(GT_FIELD_NAME, { type });
|
|
2510
|
+
}
|
|
2511
|
+
});
|
|
2512
|
+
const GTE_FIELD_NAME = "gte";
|
|
2513
|
+
const gteOperator = () => ({
|
|
2514
|
+
fieldName: GTE_FIELD_NAME,
|
|
2515
|
+
strapiOperator: "$gte",
|
|
2516
|
+
add(t, type) {
|
|
2517
|
+
t.field(GTE_FIELD_NAME, { type });
|
|
2518
|
+
}
|
|
2519
|
+
});
|
|
2520
|
+
const LT_FIELD_NAME = "lt";
|
|
2521
|
+
const ltOperator = () => ({
|
|
2522
|
+
fieldName: LT_FIELD_NAME,
|
|
2523
|
+
strapiOperator: "$lt",
|
|
2524
|
+
add(t, type) {
|
|
2525
|
+
t.field(LT_FIELD_NAME, { type });
|
|
2526
|
+
}
|
|
2527
|
+
});
|
|
2528
|
+
const LTE_FIELD_NAME = "lte";
|
|
2529
|
+
const lteOperator = () => ({
|
|
2530
|
+
fieldName: LTE_FIELD_NAME,
|
|
2531
|
+
strapiOperator: "$lte",
|
|
2532
|
+
add(t, type) {
|
|
2533
|
+
t.field(LTE_FIELD_NAME, { type });
|
|
2534
|
+
}
|
|
2535
|
+
});
|
|
2536
|
+
const NULL_FIELD_NAME = "null";
|
|
2537
|
+
const nullOperator = () => ({
|
|
2538
|
+
fieldName: NULL_FIELD_NAME,
|
|
2539
|
+
strapiOperator: "$null",
|
|
2540
|
+
add(t) {
|
|
2541
|
+
t.boolean(NULL_FIELD_NAME);
|
|
2542
|
+
}
|
|
2543
|
+
});
|
|
2544
|
+
const NOT_NULL_FIELD_NAME = "notNull";
|
|
2545
|
+
const notNullOperator = () => ({
|
|
2546
|
+
fieldName: NOT_NULL_FIELD_NAME,
|
|
2547
|
+
strapiOperator: "$notNull",
|
|
2548
|
+
add(t) {
|
|
2549
|
+
t.boolean(NOT_NULL_FIELD_NAME);
|
|
2550
|
+
}
|
|
2551
|
+
});
|
|
2552
|
+
const IN_FIELD_NAME = "in";
|
|
2553
|
+
const inOperator = () => ({
|
|
2554
|
+
fieldName: IN_FIELD_NAME,
|
|
2555
|
+
strapiOperator: "$in",
|
|
2556
|
+
add(t, type) {
|
|
2557
|
+
t.field(IN_FIELD_NAME, { type: list(type) });
|
|
2558
|
+
}
|
|
2559
|
+
});
|
|
2560
|
+
const NOT_IN_FIELD_NAME = "notIn";
|
|
2561
|
+
const notInOperator = () => ({
|
|
2562
|
+
fieldName: NOT_IN_FIELD_NAME,
|
|
2563
|
+
strapiOperator: "$notIn",
|
|
2564
|
+
add(t, type) {
|
|
2565
|
+
t.field(NOT_IN_FIELD_NAME, { type: list(type) });
|
|
2566
|
+
}
|
|
2567
|
+
});
|
|
2568
|
+
const BETWEEN_FIELD_NAME = "between";
|
|
2569
|
+
const betweenOperator = () => ({
|
|
2570
|
+
fieldName: BETWEEN_FIELD_NAME,
|
|
2571
|
+
strapiOperator: "$between",
|
|
2572
|
+
add(t, type) {
|
|
2573
|
+
t.field(BETWEEN_FIELD_NAME, { type: list(type) });
|
|
2574
|
+
}
|
|
2575
|
+
});
|
|
2576
|
+
const operators = {
|
|
2577
|
+
and: andOperator,
|
|
2578
|
+
or: orOperator,
|
|
2579
|
+
not: notOperator,
|
|
2580
|
+
eq: eqOperator,
|
|
2581
|
+
eqi: eqiOperator,
|
|
2582
|
+
ne: neOperator,
|
|
2583
|
+
nei: neiOperator,
|
|
2584
|
+
startsWith: startsWithOperator,
|
|
2585
|
+
endsWith: endsWithOperator,
|
|
2586
|
+
contains: containsOperator,
|
|
2587
|
+
notContains: notContainsOperator,
|
|
2588
|
+
containsi: containsiOperator,
|
|
2589
|
+
notContainsi: notContainsiOperator,
|
|
2590
|
+
gt: gtOperator,
|
|
2591
|
+
gte: gteOperator,
|
|
2592
|
+
lt: ltOperator,
|
|
2593
|
+
lte: lteOperator,
|
|
2594
|
+
null: nullOperator,
|
|
2595
|
+
notNull: notNullOperator,
|
|
2596
|
+
in: inOperator,
|
|
2597
|
+
notIn: notInOperator,
|
|
2598
|
+
between: betweenOperator
|
|
2599
|
+
};
|
|
2600
|
+
const operators$1 = ({ strapi: strapi2 }) => mapValues((opCtor) => opCtor({ strapi: strapi2 }), operators);
|
|
2601
|
+
const { withDefaultPagination } = pagination$1;
|
|
2602
|
+
const { hasDraftAndPublish } = contentTypes;
|
|
2603
|
+
const utils = ({ strapi: strapi2 }) => {
|
|
2604
|
+
const { service: getService } = strapi2.plugin("graphql");
|
|
2605
|
+
return {
|
|
2606
|
+
/**
|
|
2607
|
+
* Get every args for a given content type
|
|
2608
|
+
* @param {object} contentType
|
|
2609
|
+
* @param {object} options
|
|
2610
|
+
* @param {boolean} options.multiple
|
|
2611
|
+
* @return {object}
|
|
2612
|
+
*/
|
|
2613
|
+
getContentTypeArgs(contentType2, { multiple = true } = {}) {
|
|
2614
|
+
const { naming: naming2 } = getService("utils");
|
|
2615
|
+
const { args: args2 } = getService("internals");
|
|
2616
|
+
const { modelType } = contentType2;
|
|
2617
|
+
if (modelType === "component") {
|
|
2618
|
+
if (!multiple)
|
|
2619
|
+
return {};
|
|
2620
|
+
return {
|
|
2621
|
+
filters: naming2.getFiltersInputTypeName(contentType2),
|
|
2622
|
+
pagination: args2.PaginationArg,
|
|
2623
|
+
sort: args2.SortArg
|
|
2624
|
+
};
|
|
2625
|
+
}
|
|
2626
|
+
const { kind } = contentType2;
|
|
2627
|
+
if (kind === "collectionType") {
|
|
2628
|
+
if (!multiple) {
|
|
2629
|
+
return { id: "ID" };
|
|
2630
|
+
}
|
|
2631
|
+
const params = {
|
|
2632
|
+
filters: naming2.getFiltersInputTypeName(contentType2),
|
|
2633
|
+
pagination: args2.PaginationArg,
|
|
2634
|
+
sort: args2.SortArg
|
|
2635
|
+
};
|
|
2636
|
+
if (hasDraftAndPublish(contentType2)) {
|
|
2637
|
+
Object.assign(params, { publicationState: args2.PublicationStateArg });
|
|
2638
|
+
}
|
|
2639
|
+
return params;
|
|
2640
|
+
}
|
|
2641
|
+
if (kind === "singleType") {
|
|
2642
|
+
const params = {};
|
|
2643
|
+
if (hasDraftAndPublish(contentType2)) {
|
|
2644
|
+
Object.assign(params, { publicationState: args2.PublicationStateArg });
|
|
2645
|
+
}
|
|
2646
|
+
return params;
|
|
2647
|
+
}
|
|
2648
|
+
},
|
|
2649
|
+
/**
|
|
2650
|
+
* Filter an object entries and keep only those whose value is a unique scalar attribute
|
|
2651
|
+
*/
|
|
2652
|
+
getUniqueScalarAttributes(attributes2) {
|
|
2653
|
+
const { isStrapiScalar } = getService("utils").attributes;
|
|
2654
|
+
const uniqueAttributes = entries(attributes2).filter(
|
|
2655
|
+
([, attribute]) => isStrapiScalar(attribute) && "unique" in attribute && attribute.unique
|
|
2656
|
+
);
|
|
2657
|
+
return Object.fromEntries(uniqueAttributes);
|
|
2658
|
+
},
|
|
2659
|
+
/**
|
|
2660
|
+
* Map each value from an attribute to a FiltersInput type name
|
|
2661
|
+
* @param {object} attributes - The attributes object to transform
|
|
2662
|
+
* @return {Object<string, string>}
|
|
2663
|
+
*/
|
|
2664
|
+
scalarAttributesToFiltersMap(attributes2) {
|
|
2665
|
+
return mapValues((attribute) => {
|
|
2666
|
+
const { mappers: mappers2, naming: naming2 } = getService("utils");
|
|
2667
|
+
const gqlScalar = mappers2.strapiScalarToGraphQLScalar(attribute.type);
|
|
2668
|
+
return naming2.getScalarFilterInputTypeName(gqlScalar);
|
|
2669
|
+
}, attributes2);
|
|
2670
|
+
},
|
|
2671
|
+
/**
|
|
2672
|
+
* Apply basic transform to GQL args
|
|
2673
|
+
*/
|
|
2674
|
+
transformArgs(args2, {
|
|
2675
|
+
contentType: contentType2,
|
|
2676
|
+
usePagination = false
|
|
2677
|
+
}) {
|
|
2678
|
+
const { mappers: mappers2 } = getService("utils");
|
|
2679
|
+
const { config: config2 } = strapi2.plugin("graphql");
|
|
2680
|
+
const { pagination: pagination2 = {}, filters: filters2 = {} } = args2;
|
|
2681
|
+
const newArgs = omit(["pagination", "filters"], args2);
|
|
2682
|
+
if (usePagination) {
|
|
2683
|
+
const defaultLimit = config2("defaultLimit");
|
|
2684
|
+
const maxLimit = config2("maxLimit");
|
|
2685
|
+
Object.assign(
|
|
2686
|
+
newArgs,
|
|
2687
|
+
withDefaultPagination(pagination2, {
|
|
2688
|
+
maxLimit,
|
|
2689
|
+
defaults: {
|
|
2690
|
+
offset: { limit: defaultLimit },
|
|
2691
|
+
page: { pageSize: defaultLimit }
|
|
2692
|
+
}
|
|
2693
|
+
})
|
|
2694
|
+
);
|
|
2695
|
+
}
|
|
2696
|
+
if (args2.filters) {
|
|
2697
|
+
Object.assign(newArgs, {
|
|
2698
|
+
filters: mappers2.graphQLFiltersToStrapiQuery(filters2, contentType2)
|
|
2699
|
+
});
|
|
2700
|
+
}
|
|
2701
|
+
return newArgs;
|
|
2702
|
+
}
|
|
2703
|
+
};
|
|
2704
|
+
};
|
|
2705
|
+
const buildersFactories = [
|
|
2706
|
+
enums,
|
|
2707
|
+
dynamicZone,
|
|
2708
|
+
entity,
|
|
2709
|
+
entityMeta,
|
|
2710
|
+
typeBuilder,
|
|
2711
|
+
response,
|
|
2712
|
+
responseCollection,
|
|
2713
|
+
relationResponseCollection,
|
|
2714
|
+
queries,
|
|
2715
|
+
mutations,
|
|
2716
|
+
filters,
|
|
2717
|
+
inputs,
|
|
2718
|
+
genericMorph,
|
|
2719
|
+
resolvers
|
|
2720
|
+
];
|
|
2721
|
+
const builders = ({ strapi: strapi2 }) => {
|
|
2722
|
+
const buildersMap = /* @__PURE__ */ new Map();
|
|
2723
|
+
return {
|
|
2724
|
+
/**
|
|
2725
|
+
* Instantiate every builder with a strapi instance & a type registry
|
|
2726
|
+
*/
|
|
2727
|
+
new(name, registry) {
|
|
2728
|
+
const context = { strapi: strapi2, registry };
|
|
2729
|
+
const builders2 = pipe(
|
|
2730
|
+
// Create a new instance of every builders
|
|
2731
|
+
map((factory) => factory(context)),
|
|
2732
|
+
// Merge every builder into the same object
|
|
2733
|
+
reduce(merge$1, {})
|
|
2734
|
+
).call(null, buildersFactories);
|
|
2735
|
+
buildersMap.set(name, builders2);
|
|
2736
|
+
return builders2;
|
|
2737
|
+
},
|
|
2738
|
+
/**
|
|
2739
|
+
* Delete a set of builders instances from
|
|
2740
|
+
* the builders map for a given name
|
|
2741
|
+
*/
|
|
2742
|
+
delete(name) {
|
|
2743
|
+
buildersMap.delete(name);
|
|
2744
|
+
},
|
|
2745
|
+
/**
|
|
2746
|
+
* Retrieve a set of builders instances from
|
|
2747
|
+
* the builders map for a given name
|
|
2748
|
+
*/
|
|
2749
|
+
get(name) {
|
|
2750
|
+
return buildersMap.get(name);
|
|
2751
|
+
},
|
|
2752
|
+
filters: {
|
|
2753
|
+
operators: operators$1({ strapi: strapi2 })
|
|
2754
|
+
},
|
|
2755
|
+
utils: utils({ strapi: strapi2 })
|
|
2756
|
+
};
|
|
2757
|
+
};
|
|
2758
|
+
const getDefaultContentTypeConfig = () => ({
|
|
2759
|
+
enabled: true,
|
|
2760
|
+
mutations: true,
|
|
2761
|
+
queries: true,
|
|
2762
|
+
disabledActions: [],
|
|
2763
|
+
fields: /* @__PURE__ */ new Map()
|
|
2764
|
+
});
|
|
2765
|
+
const getDefaultFieldConfig = () => ({
|
|
2766
|
+
enabled: true,
|
|
2767
|
+
input: true,
|
|
2768
|
+
output: true,
|
|
2769
|
+
filters: true
|
|
2770
|
+
});
|
|
2771
|
+
const ALL_ACTIONS = "*";
|
|
2772
|
+
const createShadowCRUDManager = () => {
|
|
2773
|
+
const configs = /* @__PURE__ */ new Map();
|
|
2774
|
+
return (uid) => {
|
|
2775
|
+
if (!configs.has(uid)) {
|
|
2776
|
+
configs.set(uid, getDefaultContentTypeConfig());
|
|
2777
|
+
}
|
|
2778
|
+
return {
|
|
2779
|
+
isEnabled() {
|
|
2780
|
+
return configs.get(uid).enabled;
|
|
2781
|
+
},
|
|
2782
|
+
isDisabled() {
|
|
2783
|
+
return !this.isEnabled();
|
|
2784
|
+
},
|
|
2785
|
+
areQueriesEnabled() {
|
|
2786
|
+
return configs.get(uid).queries;
|
|
2787
|
+
},
|
|
2788
|
+
areQueriesDisabled() {
|
|
2789
|
+
return !this.areQueriesEnabled();
|
|
2790
|
+
},
|
|
2791
|
+
areMutationsEnabled() {
|
|
2792
|
+
return configs.get(uid).mutations;
|
|
2793
|
+
},
|
|
2794
|
+
areMutationsDisabled() {
|
|
2795
|
+
return !this.areMutationsEnabled();
|
|
2796
|
+
},
|
|
2797
|
+
isActionEnabled(action) {
|
|
2798
|
+
const matchingActions = [action, ALL_ACTIONS];
|
|
2799
|
+
return configs.get(uid).disabledActions.every((action2) => !matchingActions.includes(action2));
|
|
2800
|
+
},
|
|
2801
|
+
isActionDisabled(action) {
|
|
2802
|
+
return !this.isActionEnabled(action);
|
|
2803
|
+
},
|
|
2804
|
+
disable() {
|
|
2805
|
+
configs.get(uid).enabled = false;
|
|
2806
|
+
return this;
|
|
2807
|
+
},
|
|
2808
|
+
disableQueries() {
|
|
2809
|
+
configs.get(uid).queries = false;
|
|
2810
|
+
return this;
|
|
2811
|
+
},
|
|
2812
|
+
disableMutations() {
|
|
2813
|
+
configs.get(uid).mutations = false;
|
|
2814
|
+
return this;
|
|
2815
|
+
},
|
|
2816
|
+
disableAction(action) {
|
|
2817
|
+
const config2 = configs.get(uid);
|
|
2818
|
+
if (!config2.disabledActions.includes(action)) {
|
|
2819
|
+
config2.disabledActions.push(action);
|
|
2820
|
+
}
|
|
2821
|
+
return this;
|
|
2822
|
+
},
|
|
2823
|
+
disableActions(actions = []) {
|
|
2824
|
+
actions.forEach((action) => this.disableAction(action));
|
|
2825
|
+
return this;
|
|
2826
|
+
},
|
|
2827
|
+
field(fieldName) {
|
|
2828
|
+
const { fields } = configs.get(uid);
|
|
2829
|
+
if (!fields.has(fieldName)) {
|
|
2830
|
+
fields.set(fieldName, getDefaultFieldConfig());
|
|
2831
|
+
}
|
|
2832
|
+
return {
|
|
2833
|
+
isEnabled() {
|
|
2834
|
+
return fields.get(fieldName).enabled;
|
|
2835
|
+
},
|
|
2836
|
+
hasInputEnabled() {
|
|
2837
|
+
return fields.get(fieldName).input;
|
|
2838
|
+
},
|
|
2839
|
+
hasOutputEnabled() {
|
|
2840
|
+
return fields.get(fieldName).output;
|
|
2841
|
+
},
|
|
2842
|
+
hasFiltersEnabeld() {
|
|
2843
|
+
return fields.get(fieldName).filters;
|
|
2844
|
+
},
|
|
2845
|
+
disable() {
|
|
2846
|
+
fields.set(fieldName, {
|
|
2847
|
+
enabled: false,
|
|
2848
|
+
output: false,
|
|
2849
|
+
input: false,
|
|
2850
|
+
filters: false
|
|
2851
|
+
});
|
|
2852
|
+
return this;
|
|
2853
|
+
},
|
|
2854
|
+
disableOutput() {
|
|
2855
|
+
fields.get(fieldName).output = false;
|
|
2856
|
+
return this;
|
|
2857
|
+
},
|
|
2858
|
+
disableInput() {
|
|
2859
|
+
fields.get(fieldName).input = false;
|
|
2860
|
+
return this;
|
|
2861
|
+
},
|
|
2862
|
+
disableFilters() {
|
|
2863
|
+
fields.get(fieldName).filters = false;
|
|
2864
|
+
return this;
|
|
2865
|
+
}
|
|
2866
|
+
};
|
|
2867
|
+
}
|
|
2868
|
+
};
|
|
2869
|
+
};
|
|
2870
|
+
};
|
|
2871
|
+
const getDefaultState = () => ({
|
|
2872
|
+
types: [],
|
|
2873
|
+
typeDefs: [],
|
|
2874
|
+
resolvers: {},
|
|
2875
|
+
resolversConfig: {},
|
|
2876
|
+
plugins: []
|
|
2877
|
+
});
|
|
2878
|
+
const createExtension = ({ strapi: strapi2 }) => {
|
|
2879
|
+
const configs = [];
|
|
2880
|
+
return {
|
|
2881
|
+
shadowCRUD: createShadowCRUDManager(),
|
|
2882
|
+
/**
|
|
2883
|
+
* Register a new extension configuration
|
|
2884
|
+
*/
|
|
2885
|
+
use(configuration) {
|
|
2886
|
+
configs.push(configuration);
|
|
2887
|
+
return this;
|
|
2888
|
+
},
|
|
2889
|
+
/**
|
|
2890
|
+
* Convert the registered configuration into a single extension object & return it
|
|
2891
|
+
*/
|
|
2892
|
+
generate({ typeRegistry: typeRegistry2 }) {
|
|
2893
|
+
const resolveConfig = (config2) => {
|
|
2894
|
+
return typeof config2 === "function" ? config2({ strapi: strapi2, nexus, typeRegistry: typeRegistry2 }) : config2;
|
|
2895
|
+
};
|
|
2896
|
+
return configs.reduce((acc, configuration) => {
|
|
2897
|
+
const { types: types2, typeDefs, resolvers: resolvers2, resolversConfig, plugins } = resolveConfig(configuration);
|
|
2898
|
+
if (typeof typeDefs === "string") {
|
|
2899
|
+
acc.typeDefs.push(typeDefs);
|
|
2900
|
+
}
|
|
2901
|
+
if (Array.isArray(types2)) {
|
|
2902
|
+
acc.types.push(...types2);
|
|
2903
|
+
}
|
|
2904
|
+
if (Array.isArray(plugins)) {
|
|
2905
|
+
acc.plugins.push(...plugins);
|
|
2906
|
+
}
|
|
2907
|
+
if (typeof resolvers2 === "object") {
|
|
2908
|
+
acc.resolvers = merge$1(acc.resolvers, resolvers2);
|
|
2909
|
+
}
|
|
2910
|
+
if (typeof resolversConfig === "object") {
|
|
2911
|
+
acc.resolversConfig = merge$1(resolversConfig, acc.resolversConfig);
|
|
2912
|
+
}
|
|
2913
|
+
return acc;
|
|
2914
|
+
}, getDefaultState());
|
|
2915
|
+
}
|
|
2916
|
+
};
|
|
2917
|
+
};
|
|
2918
|
+
const returnTypes = () => ({
|
|
2919
|
+
toEntityResponse(value, info = {}) {
|
|
2920
|
+
const { args: args2 = {}, resourceUID } = info;
|
|
2921
|
+
return { value, info: { args: args2, resourceUID } };
|
|
2922
|
+
},
|
|
2923
|
+
toEntityResponseCollection(nodes, info = {}) {
|
|
2924
|
+
const { args: args2 = {}, resourceUID } = info;
|
|
2925
|
+
return { nodes, info: { args: args2, resourceUID } };
|
|
2926
|
+
}
|
|
2927
|
+
});
|
|
2928
|
+
const format = () => ({
|
|
2929
|
+
returnTypes: returnTypes()
|
|
2930
|
+
});
|
|
2931
|
+
const services = {
|
|
2932
|
+
builders,
|
|
2933
|
+
"content-api": contentAPI,
|
|
2934
|
+
constants,
|
|
2935
|
+
extension: createExtension,
|
|
2936
|
+
format,
|
|
2937
|
+
internals,
|
|
2938
|
+
"type-registry": typeRegistry,
|
|
2939
|
+
utils: utils$1
|
|
2940
|
+
};
|
|
2941
|
+
const index = {
|
|
2942
|
+
config,
|
|
2943
|
+
bootstrap,
|
|
2944
|
+
services
|
|
2945
|
+
};
|
|
2946
|
+
export {
|
|
2947
|
+
index as default
|
|
2948
|
+
};
|
|
2949
|
+
//# sourceMappingURL=index.mjs.map
|