@strapi/plugin-graphql 5.17.0-beta.0 → 5.18.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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var name = "@strapi/plugin-graphql";
6
- var version = "5.16.0";
6
+ var version = "5.18.0";
7
7
  var description = "Adds GraphQL endpoint with default API methods.";
8
8
  var repository = {
9
9
  type: "git",
@@ -60,9 +60,9 @@ var dependencies = {
60
60
  "@graphql-tools/schema": "10.0.3",
61
61
  "@graphql-tools/utils": "^10.1.3",
62
62
  "@koa/cors": "5.0.0",
63
- "@strapi/design-system": "2.0.0-rc.26",
64
- "@strapi/icons": "2.0.0-rc.26",
65
- "@strapi/utils": "5.16.0",
63
+ "@strapi/design-system": "2.0.0-rc.28",
64
+ "@strapi/icons": "2.0.0-rc.28",
65
+ "@strapi/utils": "5.18.0",
66
66
  graphql: "^16.8.1",
67
67
  "graphql-depth-limit": "^1.1.0",
68
68
  "graphql-playground-middleware-koa": "^1.6.21",
@@ -74,19 +74,19 @@ var dependencies = {
74
74
  pluralize: "8.0.0"
75
75
  };
76
76
  var devDependencies = {
77
- "@strapi/strapi": "5.16.0",
78
- "@strapi/types": "5.16.0",
77
+ "@strapi/strapi": "5.18.0",
78
+ "@strapi/types": "5.18.0",
79
79
  "@types/graphql-depth-limit": "1.1.5",
80
80
  "@types/koa-bodyparser": "4.3.12",
81
81
  "@types/koa__cors": "5.0.0",
82
82
  "cross-env": "^7.0.3",
83
- "eslint-config-custom": "5.16.0",
83
+ "eslint-config-custom": "5.18.0",
84
84
  koa: "2.16.1",
85
85
  react: "18.3.1",
86
86
  "react-dom": "18.3.1",
87
87
  "react-router-dom": "6.22.3",
88
88
  "styled-components": "6.1.8",
89
- tsconfig: "5.16.0",
89
+ tsconfig: "5.18.0",
90
90
  typescript: "5.4.4"
91
91
  };
92
92
  var peerDependencies = {
@@ -1,5 +1,5 @@
1
1
  var name = "@strapi/plugin-graphql";
2
- var version = "5.16.0";
2
+ var version = "5.18.0";
3
3
  var description = "Adds GraphQL endpoint with default API methods.";
4
4
  var repository = {
5
5
  type: "git",
@@ -56,9 +56,9 @@ var dependencies = {
56
56
  "@graphql-tools/schema": "10.0.3",
57
57
  "@graphql-tools/utils": "^10.1.3",
58
58
  "@koa/cors": "5.0.0",
59
- "@strapi/design-system": "2.0.0-rc.26",
60
- "@strapi/icons": "2.0.0-rc.26",
61
- "@strapi/utils": "5.16.0",
59
+ "@strapi/design-system": "2.0.0-rc.28",
60
+ "@strapi/icons": "2.0.0-rc.28",
61
+ "@strapi/utils": "5.18.0",
62
62
  graphql: "^16.8.1",
63
63
  "graphql-depth-limit": "^1.1.0",
64
64
  "graphql-playground-middleware-koa": "^1.6.21",
@@ -70,19 +70,19 @@ var dependencies = {
70
70
  pluralize: "8.0.0"
71
71
  };
72
72
  var devDependencies = {
73
- "@strapi/strapi": "5.16.0",
74
- "@strapi/types": "5.16.0",
73
+ "@strapi/strapi": "5.18.0",
74
+ "@strapi/types": "5.18.0",
75
75
  "@types/graphql-depth-limit": "1.1.5",
76
76
  "@types/koa-bodyparser": "4.3.12",
77
77
  "@types/koa__cors": "5.0.0",
78
78
  "cross-env": "^7.0.3",
79
- "eslint-config-custom": "5.16.0",
79
+ "eslint-config-custom": "5.18.0",
80
80
  koa: "2.16.1",
81
81
  react: "18.3.1",
82
82
  "react-dom": "18.3.1",
83
83
  "react-router-dom": "6.22.3",
84
84
  "styled-components": "6.1.8",
85
- tsconfig: "5.16.0",
85
+ tsconfig: "5.18.0",
86
86
  typescript: "5.4.4"
87
87
  };
88
88
  var peerDependencies = {
@@ -85,6 +85,30 @@ async function bootstrap({ strapi }) {
85
85
  const { config } = strapi.plugin('graphql');
86
86
  const path = config('endpoint');
87
87
  const landingPage = determineLandingPage(strapi);
88
+ /**
89
+ * We need the arguments passed to the root query to be available in the association resolver
90
+ * so we can forward those arguments along to any relations.
91
+ *
92
+ * In order to do that we are currently storing the arguments in context.
93
+ * There is likely a better solution, but for now this is the simplest fix we could find.
94
+ *
95
+ * @see https://github.com/strapi/strapi/issues/23524
96
+ */ const pluginAddRootQueryArgs = {
97
+ async requestDidStart () {
98
+ return {
99
+ async executionDidStart () {
100
+ return {
101
+ willResolveField ({ source, args, contextValue, info }) {
102
+ if (!source && info.operation.operation === 'query') {
103
+ // NOTE: context.rootQueryArgs is intended for internal use only
104
+ contextValue.rootQueryArgs = args;
105
+ }
106
+ }
107
+ };
108
+ }
109
+ };
110
+ }
111
+ };
88
112
  const defaultServerConfig = {
89
113
  // Schema
90
114
  schema,
@@ -101,7 +125,8 @@ async function bootstrap({ strapi }) {
101
125
  // send 400 http status instead of 200 for input validation errors
102
126
  status400ForVariableCoercionErrors: true,
103
127
  plugins: [
104
- landingPage
128
+ landingPage,
129
+ pluginAddRootQueryArgs
105
130
  ],
106
131
  cache: 'bounded'
107
132
  };
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.js","sources":["../../server/src/bootstrap.ts"],"sourcesContent":["import { isEmpty, mergeWith, isArray, isObject, isFunction } from 'lodash/fp';\nimport { ApolloServer, type ApolloServerPlugin, type ApolloServerOptions } from '@apollo/server';\nimport {\n ApolloServerPluginLandingPageLocalDefault,\n ApolloServerPluginLandingPageProductionDefault,\n} from '@apollo/server/plugin/landingPage/default';\nimport { koaMiddleware } from '@as-integrations/koa';\nimport depthLimit from 'graphql-depth-limit';\nimport bodyParser from 'koa-bodyparser';\nimport cors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\nimport type { BaseContext, DefaultContextExtends, DefaultStateExtends } from 'koa';\n\nimport { formatGraphqlError } from './format-graphql-error';\n\nconst merge = mergeWith((a, b) => {\n if (isArray(a) && isArray(b)) {\n return a.concat(b);\n }\n});\n\nexport const determineLandingPage = (strapi: Core.Strapi) => {\n const { config } = strapi.plugin('graphql');\n const utils = strapi.plugin('graphql').service('utils');\n\n /**\n * configLanding page may be one of the following:\n *\n * - true: always use \"playground\" even in production\n * - false: never show \"playground\" even in non-production\n * - undefined: default Apollo behavior (hide playground on production)\n * - a function that returns an Apollo plugin that implements renderLandingPage\n ** */\n const configLandingPage = config('landingPage');\n\n const isProduction = process.env.NODE_ENV === 'production';\n\n const localLanding = () => {\n strapi.log.debug('Apollo landing page: local');\n utils.playground.setEnabled(true);\n return ApolloServerPluginLandingPageLocalDefault();\n };\n\n const prodLanding = () => {\n strapi.log.debug('Apollo landing page: production');\n utils.playground.setEnabled(false);\n return ApolloServerPluginLandingPageProductionDefault();\n };\n\n const userLanding = (userFunction: (strapi?: Core.Strapi) => ApolloServerPlugin | boolean) => {\n strapi.log.debug('Apollo landing page: from user-defined function...');\n const result = userFunction(strapi);\n if (result === true) {\n return localLanding();\n }\n if (result === false) {\n return prodLanding();\n }\n strapi.log.debug('Apollo landing page: user-defined');\n return result;\n };\n\n // DEPRECATED, remove in Strapi v6\n const playgroundAlways = config('playgroundAlways');\n if (playgroundAlways !== undefined) {\n strapi.log.warn(\n 'The graphql config playgroundAlways is deprecated. This will be removed in Strapi 6. Please use landingPage instead. '\n );\n }\n if (playgroundAlways === false) {\n strapi.log.warn(\n 'graphql config playgroundAlways:false has no effect, please use landingPage:false to disable Graphql Playground in all environments'\n );\n }\n\n if (playgroundAlways || configLandingPage === true) {\n return localLanding();\n }\n\n // if landing page has been disabled, use production\n if (configLandingPage === false) {\n return prodLanding();\n }\n\n // If user did not define any settings, use our defaults\n if (configLandingPage === undefined) {\n return isProduction ? prodLanding() : localLanding();\n }\n\n // if user provided a landing page function, return that\n if (isFunction(configLandingPage)) {\n return userLanding(configLandingPage);\n }\n\n // If no other setting could be found, default to production settings\n strapi.log.warn(\n 'Your Graphql landing page has been disabled because there is a problem with your Graphql settings'\n );\n return prodLanding();\n};\n\nexport async function bootstrap({ strapi }: { strapi: Core.Strapi }) {\n // Generate the GraphQL schema for the content API\n const schema = strapi.plugin('graphql').service('content-api').buildSchema();\n\n if (isEmpty(schema)) {\n strapi.log.warn('The GraphQL schema has not been generated because it is empty');\n\n return;\n }\n\n const { config } = strapi.plugin('graphql');\n\n const path: string = config('endpoint');\n\n const landingPage = determineLandingPage(strapi);\n\n type CustomOptions = {\n cors: boolean;\n uploads: boolean;\n bodyParserConfig: boolean;\n };\n\n const defaultServerConfig: ApolloServerOptions<BaseContext> & CustomOptions = {\n // Schema\n schema,\n\n // Validation\n validationRules: [depthLimit(config('depthLimit') as number) as any],\n\n // Errors\n formatError: formatGraphqlError,\n\n // Misc\n cors: false,\n uploads: false,\n bodyParserConfig: true,\n // send 400 http status instead of 200 for input validation errors\n status400ForVariableCoercionErrors: true,\n plugins: [landingPage],\n\n cache: 'bounded' as const,\n };\n\n const serverConfig = merge(\n defaultServerConfig,\n config('apolloServer')\n ) as ApolloServerOptions<BaseContext> & CustomOptions;\n\n // Create a new Apollo server\n const server = new ApolloServer(serverConfig);\n\n try {\n // server.start() must be called before using server.applyMiddleware()\n await server.start();\n } catch (error) {\n if (error instanceof Error) {\n strapi.log.error('Failed to start the Apollo server', error.message);\n }\n\n throw error;\n }\n\n // Create the route handlers for Strapi\n const handler: Core.MiddlewareHandler[] = [];\n\n // add cors middleware\n if (cors) {\n handler.push(cors());\n }\n\n // add koa bodyparser middleware\n if (isObject(serverConfig.bodyParserConfig)) {\n handler.push(bodyParser(serverConfig.bodyParserConfig));\n } else if (serverConfig.bodyParserConfig) {\n handler.push(bodyParser());\n } else {\n strapi.log.debug('Body parser has been disabled for Apollo server');\n }\n\n // add the Strapi auth middleware\n handler.push((ctx, next) => {\n ctx.state.route = {\n info: {\n // Indicate it's a content API route\n type: 'content-api',\n },\n };\n\n const isPlaygroundRequest =\n ctx.request.method === 'GET' &&\n ctx.request.url === path && // Matches the GraphQL endpoint\n strapi.plugin('graphql').service('utils').playground.isEnabled() && // Only allow if the Playground is enabled\n ctx.request.header.accept?.includes('text/html'); // Specific to Playground UI loading\n\n // Skip authentication for the GraphQL Playground UI\n if (isPlaygroundRequest) {\n return next();\n }\n\n return strapi.auth.authenticate(ctx, next);\n });\n\n // add the graphql server for koa\n handler.push(\n koaMiddleware<DefaultStateExtends, DefaultContextExtends>(server, {\n // Initialize loaders for this request.\n context: async ({ ctx }) => ({\n state: ctx.state,\n koaContext: ctx,\n }),\n })\n );\n\n // now that handlers are set up, add the graphql route to our apollo server\n strapi.server.routes([\n {\n method: 'ALL',\n path,\n handler,\n config: {\n auth: false,\n },\n },\n ]);\n\n // Register destroy behavior\n // We're doing it here instead of exposing a destroy method to the strapi-server.js\n // file since we need to have access to the ApolloServer instance\n strapi.plugin('graphql').destroy = async () => {\n await server.stop();\n };\n}\n"],"names":["merge","mergeWith","a","b","isArray","concat","determineLandingPage","strapi","config","plugin","utils","service","configLandingPage","isProduction","process","env","NODE_ENV","localLanding","log","debug","playground","setEnabled","ApolloServerPluginLandingPageLocalDefault","prodLanding","ApolloServerPluginLandingPageProductionDefault","userLanding","userFunction","result","playgroundAlways","undefined","warn","isFunction","bootstrap","schema","buildSchema","isEmpty","path","landingPage","defaultServerConfig","validationRules","depthLimit","formatError","formatGraphqlError","cors","uploads","bodyParserConfig","status400ForVariableCoercionErrors","plugins","cache","serverConfig","server","ApolloServer","start","error","Error","message","handler","push","isObject","bodyParser","ctx","next","state","route","info","type","isPlaygroundRequest","request","method","url","isEnabled","header","accept","includes","auth","authenticate","koaMiddleware","context","koaContext","routes","destroy","stop"],"mappings":";;;;;;;;;;;AAgBA,MAAMA,KAAAA,GAAQC,YAAU,CAAA,CAACC,CAAGC,EAAAA,CAAAA,GAAAA;IAC1B,IAAIC,UAAAA,CAAQF,CAAME,CAAAA,IAAAA,UAAAA,CAAQD,CAAI,CAAA,EAAA;QAC5B,OAAOD,CAAAA,CAAEG,MAAM,CAACF,CAAAA,CAAAA;AAClB;AACF,CAAA,CAAA;AAEO,MAAMG,uBAAuB,CAACC,MAAAA,GAAAA;AACnC,IAAA,MAAM,EAAEC,MAAM,EAAE,GAAGD,MAAAA,CAAOE,MAAM,CAAC,SA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A,GAAAA,CAAIO,OAAO,CAACC,MAAM,KAAK,KACvBR,IAAAA,GAAAA,CAAIO,OAAO,CAACE,GAAG,KAAKjC;QACpB7B,MAAOE,CAAAA,MAAM,CAAC,SAAA,CAAA,CAAWE,OAAO,CAAC,SAASS,UAAU,CAACkD,SAAS,EAAA;QAC9DV,GAAIO,CAAAA,OAAO,CAACI,MAAM,CAACC,MAAM,EAAEC,QAAAA,CAAS;;AAGtC,QAAA,IAAIP,mBAAqB,EAAA;YACvB,OAAOL,IAAAA,EAAAA;AACT;AAEA,QAAA,OAAOtD,MAAOmE,CAAAA,IAAI,CAACC,YAAY,CAACf,GAAKC,EAAAA,IAAAA,CAAAA;AACvC,KAAA,CAAA;;IAGAL,OAAQC,CAAAA,IAAI,CACVmB,iBAAAA,CAA0D1B,QAAQ,EAAA;;AAEhE2B,QAAAA,OAAAA,EAAS,OAAO,EAAEjB,GAAG,EAAE,IAAM;AAC3BE,gBAAAA,KAAAA,EAAOF,IAAIE,KAAK;gBAChBgB,UAAYlB,EAAAA;aACd;AACF,KAAA,CAAA,CAAA;;IAIFrD,MAAO2C,CAAAA,MAAM,CAAC6B,MAAM,CAAC;AACnB,QAAA;YACEX,MAAQ,EAAA,KAAA;AACRhC,YAAAA,IAAAA;AACAoB,YAAAA,OAAAA;YACAhD,MAAQ,EAAA;gBACNkE,IAAM,EAAA;AACR;AACF;AACD,KAAA,CAAA;;;;AAKDnE,IAAAA,MAAAA,CAAOE,MAAM,CAAC,SAAWuE,CAAAA,CAAAA,OAAO,GAAG,UAAA;AACjC,QAAA,MAAM9B,SAAO+B,IAAI,EAAA;AACnB,KAAA;AACF;;;;;"}
1
+ {"version":3,"file":"bootstrap.js","sources":["../../server/src/bootstrap.ts"],"sourcesContent":["import { isEmpty, mergeWith, isArray, isObject, isFunction } from 'lodash/fp';\nimport { ApolloServer, type ApolloServerPlugin, type ApolloServerOptions } from '@apollo/server';\nimport {\n ApolloServerPluginLandingPageLocalDefault,\n ApolloServerPluginLandingPageProductionDefault,\n} from '@apollo/server/plugin/landingPage/default';\nimport { koaMiddleware } from '@as-integrations/koa';\nimport depthLimit from 'graphql-depth-limit';\nimport bodyParser from 'koa-bodyparser';\nimport cors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\nimport type { BaseContext, DefaultContextExtends, DefaultStateExtends } from 'koa';\n\nimport { formatGraphqlError } from './format-graphql-error';\n\nconst merge = mergeWith((a, b) => {\n if (isArray(a) && isArray(b)) {\n return a.concat(b);\n }\n});\n\ntype StrapiGraphQLContext = BaseContext & {\n rootQueryArgs?: Record<string, unknown>;\n};\n\nexport const determineLandingPage = (\n strapi: Core.Strapi\n): ApolloServerPlugin<StrapiGraphQLContext> => {\n const { config } = strapi.plugin('graphql');\n const utils = strapi.plugin('graphql').service('utils');\n\n /**\n * configLanding page may be one of the following:\n *\n * - true: always use \"playground\" even in production\n * - false: never show \"playground\" even in non-production\n * - undefined: default Apollo behavior (hide playground on production)\n * - a function that returns an Apollo plugin that implements renderLandingPage\n ** */\n const configLandingPage = config('landingPage');\n\n const isProduction = process.env.NODE_ENV === 'production';\n\n const localLanding = () => {\n strapi.log.debug('Apollo landing page: local');\n utils.playground.setEnabled(true);\n return ApolloServerPluginLandingPageLocalDefault();\n };\n\n const prodLanding = () => {\n strapi.log.debug('Apollo landing page: production');\n utils.playground.setEnabled(false);\n return ApolloServerPluginLandingPageProductionDefault();\n };\n\n const userLanding = (userFunction: (strapi?: Core.Strapi) => ApolloServerPlugin | boolean) => {\n strapi.log.debug('Apollo landing page: from user-defined function...');\n const result = userFunction(strapi);\n if (result === true) {\n return localLanding();\n }\n if (result === false) {\n return prodLanding();\n }\n strapi.log.debug('Apollo landing page: user-defined');\n return result;\n };\n\n // DEPRECATED, remove in Strapi v6\n const playgroundAlways = config('playgroundAlways');\n if (playgroundAlways !== undefined) {\n strapi.log.warn(\n 'The graphql config playgroundAlways is deprecated. This will be removed in Strapi 6. Please use landingPage instead. '\n );\n }\n if (playgroundAlways === false) {\n strapi.log.warn(\n 'graphql config playgroundAlways:false has no effect, please use landingPage:false to disable Graphql Playground in all environments'\n );\n }\n\n if (playgroundAlways || configLandingPage === true) {\n return localLanding();\n }\n\n // if landing page has been disabled, use production\n if (configLandingPage === false) {\n return prodLanding();\n }\n\n // If user did not define any settings, use our defaults\n if (configLandingPage === undefined) {\n return isProduction ? prodLanding() : localLanding();\n }\n\n // if user provided a landing page function, return that\n if (isFunction(configLandingPage)) {\n return userLanding(configLandingPage);\n }\n\n // If no other setting could be found, default to production settings\n strapi.log.warn(\n 'Your Graphql landing page has been disabled because there is a problem with your Graphql settings'\n );\n return prodLanding();\n};\n\nexport async function bootstrap({ strapi }: { strapi: Core.Strapi }) {\n // Generate the GraphQL schema for the content API\n const schema = strapi.plugin('graphql').service('content-api').buildSchema();\n\n if (isEmpty(schema)) {\n strapi.log.warn('The GraphQL schema has not been generated because it is empty');\n\n return;\n }\n\n const { config } = strapi.plugin('graphql');\n\n const path: string = config('endpoint');\n\n const landingPage = determineLandingPage(strapi);\n /**\n * We need the arguments passed to the root query to be available in the association resolver\n * so we can forward those arguments along to any relations.\n *\n * In order to do that we are currently storing the arguments in context.\n * There is likely a better solution, but for now this is the simplest fix we could find.\n *\n * @see https://github.com/strapi/strapi/issues/23524\n */\n const pluginAddRootQueryArgs: ApolloServerPlugin<StrapiGraphQLContext> = {\n async requestDidStart() {\n return {\n async executionDidStart() {\n return {\n willResolveField({ source, args, contextValue, info }) {\n if (!source && info.operation.operation === 'query') {\n // NOTE: context.rootQueryArgs is intended for internal use only\n contextValue.rootQueryArgs = args;\n }\n },\n };\n },\n };\n },\n };\n\n type CustomOptions = {\n cors: boolean;\n uploads: boolean;\n bodyParserConfig: boolean;\n };\n\n const defaultServerConfig: ApolloServerOptions<StrapiGraphQLContext> & CustomOptions = {\n // Schema\n schema,\n\n // Validation\n validationRules: [depthLimit(config('depthLimit') as number) as any],\n\n // Errors\n formatError: formatGraphqlError,\n\n // Misc\n cors: false,\n uploads: false,\n bodyParserConfig: true,\n // send 400 http status instead of 200 for input validation errors\n status400ForVariableCoercionErrors: true,\n plugins: [landingPage, pluginAddRootQueryArgs],\n\n cache: 'bounded' as const,\n };\n\n const serverConfig = merge(\n defaultServerConfig,\n config('apolloServer')\n ) as ApolloServerOptions<StrapiGraphQLContext> & CustomOptions;\n\n // Create a new Apollo server\n const server = new ApolloServer(serverConfig);\n\n try {\n // server.start() must be called before using server.applyMiddleware()\n await server.start();\n } catch (error) {\n if (error instanceof Error) {\n strapi.log.error('Failed to start the Apollo server', error.message);\n }\n\n throw error;\n }\n\n // Create the route handlers for Strapi\n const handler: Core.MiddlewareHandler[] = [];\n\n // add cors middleware\n if (cors) {\n handler.push(cors());\n }\n\n // add koa bodyparser middleware\n if (isObject(serverConfig.bodyParserConfig)) {\n handler.push(bodyParser(serverConfig.bodyParserConfig));\n } else if (serverConfig.bodyParserConfig) {\n handler.push(bodyParser());\n } else {\n strapi.log.debug('Body parser has been disabled for Apollo server');\n }\n\n // add the Strapi auth middleware\n handler.push((ctx, next) => {\n ctx.state.route = {\n info: {\n // Indicate it's a content API route\n type: 'content-api',\n },\n };\n\n const isPlaygroundRequest =\n ctx.request.method === 'GET' &&\n ctx.request.url === path && // Matches the GraphQL endpoint\n strapi.plugin('graphql').service('utils').playground.isEnabled() && // Only allow if the Playground is enabled\n ctx.request.header.accept?.includes('text/html'); // Specific to Playground UI loading\n\n // Skip authentication for the GraphQL Playground UI\n if (isPlaygroundRequest) {\n return next();\n }\n\n return strapi.auth.authenticate(ctx, next);\n });\n\n // add the graphql server for koa\n handler.push(\n koaMiddleware<DefaultStateExtends, DefaultContextExtends>(server, {\n // Initialize loaders for this request.\n context: async ({ ctx }) => ({\n state: ctx.state,\n koaContext: ctx,\n }),\n })\n );\n\n // now that handlers are set up, add the graphql route to our apollo server\n strapi.server.routes([\n {\n method: 'ALL',\n path,\n handler,\n config: {\n auth: false,\n },\n },\n ]);\n\n // Register destroy behavior\n // We're doing it here instead of exposing a destroy method to the strapi-server.js\n // file since we need to have access to the ApolloServer instance\n strapi.plugin('graphql').destroy = async () => {\n await server.stop();\n };\n}\n"],"names":["merge","mergeWith","a","b","isArray","concat","determineLandingPage","strapi","config","plugin","utils","service","configLandingPage","isProduction","process","env","NODE_ENV","localLanding","log","debug","playground","setEnabled","ApolloServerPluginLandingPageLocalDefault","prodLanding","ApolloServerPluginLandingPageProductionDefault","userLanding","userFunction","result","playgroundAlways","undefined","warn","isFunction","bootstrap","schema","buildSchema","isEmpty","path","landingPage","pluginAddRootQueryArgs","requestDidStart","executionDidStart","willResolveField","source","args","contextValue","info","operation","rootQueryArgs","defaultServerConfig","validationRules","depthLimit","formatError","formatGraphqlError","cors","uploads","bodyParserConfig","status400ForVariableCoercionErrors","plugins","cache","serverConfig","server","ApolloServer","start","error","Error","message","handler","push","isObject","bodyParser","ctx","next","state","route","type","isPlaygroundRequest","request","method","url","isEnabled","header","accept","includes","auth","authenticate","koaMiddleware","context","koaContext","routes","destroy","stop"],"mappings":";;;;;;;;;;;AAgBA,MAAMA,KAAAA,GAAQC,YAAU,CAAA,CAACC,CAAGC,EAAAA,CAAAA,GAAAA;IAC1B,IAAIC,UAAAA,CAAQF,CAAME,CAAAA,IAAAA,UAAAA,CAAQD,CAAI,CAAA,EAAA;QAC5B,OAAOD,CAAAA,CAAEG,MAAM,CAACF,CAAAA,CAAAA;AAClB;AACF,CAAA,CAAA;AAMO,MAAMG,uBAAuB,CAClCC,MAAAA,GAAAA;AAEA,IAAA,MAAM,EAAEC,MAAM,EAAE,GAAGD,MAAAA,CAAOE,MAAM,CAAC,SAAA,CAAA;AACjC,IAAA,MAAMC,QAAQH,MAAOE,CAAAA,MAAM,CAAC,SAAA,CAAA,CAAWE,OAAO,CAAC,OAAA,CAAA;AAE/C;;;;;;;SAQA,MAAMC,oBAAoBJ,MAAO,CAAA,aAAA,CAAA;AAEjC,IAAA,MAAMK,YAAeC,GAAAA,OAAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,YAAA;AA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;;;"}
@@ -83,6 +83,30 @@ async function bootstrap({ strapi }) {
83
83
  const { config } = strapi.plugin('graphql');
84
84
  const path = config('endpoint');
85
85
  const landingPage = determineLandingPage(strapi);
86
+ /**
87
+ * We need the arguments passed to the root query to be available in the association resolver
88
+ * so we can forward those arguments along to any relations.
89
+ *
90
+ * In order to do that we are currently storing the arguments in context.
91
+ * There is likely a better solution, but for now this is the simplest fix we could find.
92
+ *
93
+ * @see https://github.com/strapi/strapi/issues/23524
94
+ */ const pluginAddRootQueryArgs = {
95
+ async requestDidStart () {
96
+ return {
97
+ async executionDidStart () {
98
+ return {
99
+ willResolveField ({ source, args, contextValue, info }) {
100
+ if (!source && info.operation.operation === 'query') {
101
+ // NOTE: context.rootQueryArgs is intended for internal use only
102
+ contextValue.rootQueryArgs = args;
103
+ }
104
+ }
105
+ };
106
+ }
107
+ };
108
+ }
109
+ };
86
110
  const defaultServerConfig = {
87
111
  // Schema
88
112
  schema,
@@ -99,7 +123,8 @@ async function bootstrap({ strapi }) {
99
123
  // send 400 http status instead of 200 for input validation errors
100
124
  status400ForVariableCoercionErrors: true,
101
125
  plugins: [
102
- landingPage
126
+ landingPage,
127
+ pluginAddRootQueryArgs
103
128
  ],
104
129
  cache: 'bounded'
105
130
  };
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.mjs","sources":["../../server/src/bootstrap.ts"],"sourcesContent":["import { isEmpty, mergeWith, isArray, isObject, isFunction } from 'lodash/fp';\nimport { ApolloServer, type ApolloServerPlugin, type ApolloServerOptions } from '@apollo/server';\nimport {\n ApolloServerPluginLandingPageLocalDefault,\n ApolloServerPluginLandingPageProductionDefault,\n} from '@apollo/server/plugin/landingPage/default';\nimport { koaMiddleware } from '@as-integrations/koa';\nimport depthLimit from 'graphql-depth-limit';\nimport bodyParser from 'koa-bodyparser';\nimport cors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\nimport type { BaseContext, DefaultContextExtends, DefaultStateExtends } from 'koa';\n\nimport { formatGraphqlError } from './format-graphql-error';\n\nconst merge = mergeWith((a, b) => {\n if (isArray(a) && isArray(b)) {\n return a.concat(b);\n }\n});\n\nexport const determineLandingPage = (strapi: Core.Strapi) => {\n const { config } = strapi.plugin('graphql');\n const utils = strapi.plugin('graphql').service('utils');\n\n /**\n * configLanding page may be one of the following:\n *\n * - true: always use \"playground\" even in production\n * - false: never show \"playground\" even in non-production\n * - undefined: default Apollo behavior (hide playground on production)\n * - a function that returns an Apollo plugin that implements renderLandingPage\n ** */\n const configLandingPage = config('landingPage');\n\n const isProduction = process.env.NODE_ENV === 'production';\n\n const localLanding = () => {\n strapi.log.debug('Apollo landing page: local');\n utils.playground.setEnabled(true);\n return ApolloServerPluginLandingPageLocalDefault();\n };\n\n const prodLanding = () => {\n strapi.log.debug('Apollo landing page: production');\n utils.playground.setEnabled(false);\n return ApolloServerPluginLandingPageProductionDefault();\n };\n\n const userLanding = (userFunction: (strapi?: Core.Strapi) => ApolloServerPlugin | boolean) => {\n strapi.log.debug('Apollo landing page: from user-defined function...');\n const result = userFunction(strapi);\n if (result === true) {\n return localLanding();\n }\n if (result === false) {\n return prodLanding();\n }\n strapi.log.debug('Apollo landing page: user-defined');\n return result;\n };\n\n // DEPRECATED, remove in Strapi v6\n const playgroundAlways = config('playgroundAlways');\n if (playgroundAlways !== undefined) {\n strapi.log.warn(\n 'The graphql config playgroundAlways is deprecated. This will be removed in Strapi 6. Please use landingPage instead. '\n );\n }\n if (playgroundAlways === false) {\n strapi.log.warn(\n 'graphql config playgroundAlways:false has no effect, please use landingPage:false to disable Graphql Playground in all environments'\n );\n }\n\n if (playgroundAlways || configLandingPage === true) {\n return localLanding();\n }\n\n // if landing page has been disabled, use production\n if (configLandingPage === false) {\n return prodLanding();\n }\n\n // If user did not define any settings, use our defaults\n if (configLandingPage === undefined) {\n return isProduction ? prodLanding() : localLanding();\n }\n\n // if user provided a landing page function, return that\n if (isFunction(configLandingPage)) {\n return userLanding(configLandingPage);\n }\n\n // If no other setting could be found, default to production settings\n strapi.log.warn(\n 'Your Graphql landing page has been disabled because there is a problem with your Graphql settings'\n );\n return prodLanding();\n};\n\nexport async function bootstrap({ strapi }: { strapi: Core.Strapi }) {\n // Generate the GraphQL schema for the content API\n const schema = strapi.plugin('graphql').service('content-api').buildSchema();\n\n if (isEmpty(schema)) {\n strapi.log.warn('The GraphQL schema has not been generated because it is empty');\n\n return;\n }\n\n const { config } = strapi.plugin('graphql');\n\n const path: string = config('endpoint');\n\n const landingPage = determineLandingPage(strapi);\n\n type CustomOptions = {\n cors: boolean;\n uploads: boolean;\n bodyParserConfig: boolean;\n };\n\n const defaultServerConfig: ApolloServerOptions<BaseContext> & CustomOptions = {\n // Schema\n schema,\n\n // Validation\n validationRules: [depthLimit(config('depthLimit') as number) as any],\n\n // Errors\n formatError: formatGraphqlError,\n\n // Misc\n cors: false,\n uploads: false,\n bodyParserConfig: true,\n // send 400 http status instead of 200 for input validation errors\n status400ForVariableCoercionErrors: true,\n plugins: [landingPage],\n\n cache: 'bounded' as const,\n };\n\n const serverConfig = merge(\n defaultServerConfig,\n config('apolloServer')\n ) as ApolloServerOptions<BaseContext> & CustomOptions;\n\n // Create a new Apollo server\n const server = new ApolloServer(serverConfig);\n\n try {\n // server.start() must be called before using server.applyMiddleware()\n await server.start();\n } catch (error) {\n if (error instanceof Error) {\n strapi.log.error('Failed to start the Apollo server', error.message);\n }\n\n throw error;\n }\n\n // Create the route handlers for Strapi\n const handler: Core.MiddlewareHandler[] = [];\n\n // add cors middleware\n if (cors) {\n handler.push(cors());\n }\n\n // add koa bodyparser middleware\n if (isObject(serverConfig.bodyParserConfig)) {\n handler.push(bodyParser(serverConfig.bodyParserConfig));\n } else if (serverConfig.bodyParserConfig) {\n handler.push(bodyParser());\n } else {\n strapi.log.debug('Body parser has been disabled for Apollo server');\n }\n\n // add the Strapi auth middleware\n handler.push((ctx, next) => {\n ctx.state.route = {\n info: {\n // Indicate it's a content API route\n type: 'content-api',\n },\n };\n\n const isPlaygroundRequest =\n ctx.request.method === 'GET' &&\n ctx.request.url === path && // Matches the GraphQL endpoint\n strapi.plugin('graphql').service('utils').playground.isEnabled() && // Only allow if the Playground is enabled\n ctx.request.header.accept?.includes('text/html'); // Specific to Playground UI loading\n\n // Skip authentication for the GraphQL Playground UI\n if (isPlaygroundRequest) {\n return next();\n }\n\n return strapi.auth.authenticate(ctx, next);\n });\n\n // add the graphql server for koa\n handler.push(\n koaMiddleware<DefaultStateExtends, DefaultContextExtends>(server, {\n // Initialize loaders for this request.\n context: async ({ ctx }) => ({\n state: ctx.state,\n koaContext: ctx,\n }),\n })\n );\n\n // now that handlers are set up, add the graphql route to our apollo server\n strapi.server.routes([\n {\n method: 'ALL',\n path,\n handler,\n config: {\n auth: false,\n },\n },\n ]);\n\n // Register destroy behavior\n // We're doing it here instead of exposing a destroy method to the strapi-server.js\n // file since we need to have access to the ApolloServer instance\n strapi.plugin('graphql').destroy = async () => {\n await server.stop();\n };\n}\n"],"names":["merge","mergeWith","a","b","isArray","concat","determineLandingPage","strapi","config","plugin","utils","service","configLandingPage","isProduction","process","env","NODE_ENV","localLanding","log","debug","playground","setEnabled","ApolloServerPluginLandingPageLocalDefault","prodLanding","ApolloServerPluginLandingPageProductionDefault","userLanding","userFunction","result","playgroundAlways","undefined","warn","isFunction","bootstrap","schema","buildSchema","isEmpty","path","landingPage","defaultServerConfig","validationRules","depthLimit","formatError","formatGraphqlError","cors","uploads","bodyParserConfig","status400ForVariableCoercionErrors","plugins","cache","serverConfig","server","ApolloServer","start","error","Error","message","handler","push","isObject","bodyParser","ctx","next","state","route","info","type","isPlaygroundRequest","request","method","url","isEnabled","header","accept","includes","auth","authenticate","koaMiddleware","context","koaContext","routes","destroy","stop"],"mappings":";;;;;;;;;AAgBA,MAAMA,KAAAA,GAAQC,SAAU,CAAA,CAACC,CAAGC,EAAAA,CAAAA,GAAAA;IAC1B,IAAIC,OAAAA,CAAQF,CAAME,CAAAA,IAAAA,OAAAA,CAAQD,CAAI,CAAA,EAAA;QAC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ap.mjs","sources":["../../server/src/bootstrap.ts"],"sourcesContent":["import { isEmpty, mergeWith, isArray, isObject, isFunction } from 'lodash/fp';\nimport { ApolloServer, type ApolloServerPlugin, type ApolloServerOptions } from '@apollo/server';\nimport {\n ApolloServerPluginLandingPageLocalDefault,\n ApolloServerPluginLandingPageProductionDefault,\n} from '@apollo/server/plugin/landingPage/default';\nimport { koaMiddleware } from '@as-integrations/koa';\nimport depthLimit from 'graphql-depth-limit';\nimport bodyParser from 'koa-bodyparser';\nimport cors from '@koa/cors';\n\nimport type { Core } from '@strapi/types';\nimport type { BaseContext, DefaultContextExtends, DefaultStateExtends } from 'koa';\n\nimport { formatGraphqlError } from './format-graphql-error';\n\nconst merge = mergeWith((a, b) => {\n if (isArray(a) && isArray(b)) {\n return a.concat(b);\n }\n});\n\ntype StrapiGraphQLContext = BaseContext & {\n rootQueryArgs?: Record<string, unknown>;\n};\n\nexport const determineLandingPage = (\n strapi: Core.Strapi\n): ApolloServerPlugin<StrapiGraphQLContext> => {\n const { config } = strapi.plugin('graphql');\n const utils = strapi.plugin('graphql').service('utils');\n\n /**\n * configLanding page may be one of the following:\n *\n * - true: always use \"playground\" even in production\n * - false: never show \"playground\" even in non-production\n * - undefined: default Apollo behavior (hide playground on production)\n * - a function that returns an Apollo plugin that implements renderLandingPage\n ** */\n const configLandingPage = config('landingPage');\n\n const isProduction = process.env.NODE_ENV === 'production';\n\n const localLanding = () => {\n strapi.log.debug('Apollo landing page: local');\n utils.playground.setEnabled(true);\n return ApolloServerPluginLandingPageLocalDefault();\n };\n\n const prodLanding = () => {\n strapi.log.debug('Apollo landing page: production');\n utils.playground.setEnabled(false);\n return ApolloServerPluginLandingPageProductionDefault();\n };\n\n const userLanding = (userFunction: (strapi?: Core.Strapi) => ApolloServerPlugin | boolean) => {\n strapi.log.debug('Apollo landing page: from user-defined function...');\n const result = userFunction(strapi);\n if (result === true) {\n return localLanding();\n }\n if (result === false) {\n return prodLanding();\n }\n strapi.log.debug('Apollo landing page: user-defined');\n return result;\n };\n\n // DEPRECATED, remove in Strapi v6\n const playgroundAlways = config('playgroundAlways');\n if (playgroundAlways !== undefined) {\n strapi.log.warn(\n 'The graphql config playgroundAlways is deprecated. This will be removed in Strapi 6. Please use landingPage instead. '\n );\n }\n if (playgroundAlways === false) {\n strapi.log.warn(\n 'graphql config playgroundAlways:false has no effect, please use landingPage:false to disable Graphql Playground in all environments'\n );\n }\n\n if (playgroundAlways || configLandingPage === true) {\n return localLanding();\n }\n\n // if landing page has been disabled, use production\n if (configLandingPage === false) {\n return prodLanding();\n }\n\n // If user did not define any settings, use our defaults\n if (configLandingPage === undefined) {\n return isProduction ? prodLanding() : localLanding();\n }\n\n // if user provided a landing page function, return that\n if (isFunction(configLandingPage)) {\n return userLanding(configLandingPage);\n }\n\n // If no other setting could be found, default to production settings\n strapi.log.warn(\n 'Your Graphql landing page has been disabled because there is a problem with your Graphql settings'\n );\n return prodLanding();\n};\n\nexport async function bootstrap({ strapi }: { strapi: Core.Strapi }) {\n // Generate the GraphQL schema for the content API\n const schema = strapi.plugin('graphql').service('content-api').buildSchema();\n\n if (isEmpty(schema)) {\n strapi.log.warn('The GraphQL schema has not been generated because it is empty');\n\n return;\n }\n\n const { config } = strapi.plugin('graphql');\n\n const path: string = config('endpoint');\n\n const landingPage = determineLandingPage(strapi);\n /**\n * We need the arguments passed to the root query to be available in the association resolver\n * so we can forward those arguments along to any relations.\n *\n * In order to do that we are currently storing the arguments in context.\n * There is likely a better solution, but for now this is the simplest fix we could find.\n *\n * @see https://github.com/strapi/strapi/issues/23524\n */\n const pluginAddRootQueryArgs: ApolloServerPlugin<StrapiGraphQLContext> = {\n async requestDidStart() {\n return {\n async executionDidStart() {\n return {\n willResolveField({ source, args, contextValue, info }) {\n if (!source && info.operation.operation === 'query') {\n // NOTE: context.rootQueryArgs is intended for internal use only\n contextValue.rootQueryArgs = args;\n }\n },\n };\n },\n };\n },\n };\n\n type CustomOptions = {\n cors: boolean;\n uploads: boolean;\n bodyParserConfig: boolean;\n };\n\n const defaultServerConfig: ApolloServerOptions<StrapiGraphQLContext> & CustomOptions = {\n // Schema\n schema,\n\n // Validation\n validationRules: [depthLimit(config('depthLimit') as number) as any],\n\n // Errors\n formatError: formatGraphqlError,\n\n // Misc\n cors: false,\n uploads: false,\n bodyParserConfig: true,\n // send 400 http status instead of 200 for input validation errors\n status400ForVariableCoercionErrors: true,\n plugins: [landingPage, pluginAddRootQueryArgs],\n\n cache: 'bounded' as const,\n };\n\n const serverConfig = merge(\n defaultServerConfig,\n config('apolloServer')\n ) as ApolloServerOptions<StrapiGraphQLContext> & CustomOptions;\n\n // Create a new Apollo server\n const server = new ApolloServer(serverConfig);\n\n try {\n // server.start() must be called before using server.applyMiddleware()\n await server.start();\n } catch (error) {\n if (error instanceof Error) {\n strapi.log.error('Failed to start the Apollo server', error.message);\n }\n\n throw error;\n }\n\n // Create the route handlers for Strapi\n const handler: Core.MiddlewareHandler[] = [];\n\n // add cors middleware\n if (cors) {\n handler.push(cors());\n }\n\n // add koa bodyparser middleware\n if (isObject(serverConfig.bodyParserConfig)) {\n handler.push(bodyParser(serverConfig.bodyParserConfig));\n } else if (serverConfig.bodyParserConfig) {\n handler.push(bodyParser());\n } else {\n strapi.log.debug('Body parser has been disabled for Apollo server');\n }\n\n // add the Strapi auth middleware\n handler.push((ctx, next) => {\n ctx.state.route = {\n info: {\n // Indicate it's a content API route\n type: 'content-api',\n },\n };\n\n const isPlaygroundRequest =\n ctx.request.method === 'GET' &&\n ctx.request.url === path && // Matches the GraphQL endpoint\n strapi.plugin('graphql').service('utils').playground.isEnabled() && // Only allow if the Playground is enabled\n ctx.request.header.accept?.includes('text/html'); // Specific to Playground UI loading\n\n // Skip authentication for the GraphQL Playground UI\n if (isPlaygroundRequest) {\n return next();\n }\n\n return strapi.auth.authenticate(ctx, next);\n });\n\n // add the graphql server for koa\n handler.push(\n koaMiddleware<DefaultStateExtends, DefaultContextExtends>(server, {\n // Initialize loaders for this request.\n context: async ({ ctx }) => ({\n state: ctx.state,\n koaContext: ctx,\n }),\n })\n );\n\n // now that handlers are set up, add the graphql route to our apollo server\n strapi.server.routes([\n {\n method: 'ALL',\n path,\n handler,\n config: {\n auth: false,\n },\n },\n ]);\n\n // Register destroy behavior\n // We're doing it here instead of exposing a destroy method to the strapi-server.js\n // file since we need to have access to the ApolloServer instance\n strapi.plugin('graphql').destroy = async () => {\n await server.stop();\n };\n}\n"],"names":["merge","mergeWith","a","b","isArray","concat","determineLandingPage","strapi","config","plugin","utils","service","configLandingPage","isProduction","process","env","NODE_ENV","localLanding","log","debug","playground","setEnabled","ApolloServerPluginLandingPageLocalDefault","prodLanding","ApolloServerPluginLandingPageProductionDefault","userLanding","userFunction","result","playgroundAlways","undefined","warn","isFunction","bootstrap","schema","buildSchema","isEmpty","path","landingPage","pluginAddRootQueryArgs","requestDidStart","executionDidStart","willResolveField","source","args","contextValue","info","operation","rootQueryArgs","defaultServerConfig","validationRules","depthLimit","formatError","formatGraphqlError","cors","uploads","bodyParserConfig","status400ForVariableCoercionErrors","plugins","cache","serverConfig","server","ApolloServer","start","error","Error","message","handler","push","isObject","bodyParser","ctx","next","state","route","type","isPlaygroundRequest","request","method","url","isEnabled","header","accept","includes","auth","authenticate","koaMiddleware","context","koaContext","routes","destroy","stop"],"mappings":";;;;;;;;;AAgBA,MAAMA,KAAAA,GAAQC,SAAU,CAAA,CAACC,CAAGC,EAAAA,CAAAA,GAAAA;IAC1B,IAAIC,OAAAA,CAAQF,CAAME,CAAAA,IAAAA,OAAAA,CAAQD,CAAI,CAAA,EAAA;QAC5B,OAAOD,CAAAA,CAAEG,MAAM,CAACF,CAAAA,CAAAA;AAClB;AACF,CAAA,CAAA;AAMO,MAAMG,uBAAuB,CAClCC,MAAAA,GAAAA;AAEA,IAAA,MAAM,EAAEC,MAAM,EAAE,GAAGD,MAAAA,CAAOE,MAAM,CAAC,SAAA,CAAA;AACjC,IAAA,MAAMC,QAAQH,MAAOE,CAAAA,MAAM,CAAC,SA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IAAM,EAAA;AACR;AACF;AACD,KAAA,CAAA;;;;AAKD5E,IAAAA,MAAAA,CAAOE,MAAM,CAAC,SAAWgF,CAAAA,CAAAA,OAAO,GAAG,UAAA;AACjC,QAAA,MAAM7B,OAAO8B,IAAI,EAAA;AACnB,KAAA;AACF;;;;"}
@@ -34,14 +34,14 @@ var associationResolvers = (({ strapi })=>{
34
34
  auth
35
35
  });
36
36
  const transformedQuery = strapi.get('query-params').transform(targetUID, sanitizedQuery);
37
- const defaultFilters = {
37
+ const isTargetDraftAndPublishContentType = utils.contentTypes.hasDraftAndPublish(targetContentType);
38
+ const defaultFilters = isTargetDraftAndPublishContentType ? {
38
39
  where: {
39
- // Return the same draft and publish version as the parent
40
40
  publishedAt: {
41
- $notNull: 'publishedAt' in parent ? parent.publishedAt !== null : true
41
+ $notNull: context.rootQueryArgs?.status ? context.rootQueryArgs?.status === 'published' : true
42
42
  }
43
43
  }
44
- };
44
+ } : {};
45
45
  const dbQuery = fp.merge(defaultFilters, transformedQuery);
46
46
  const data = await strapi.db?.query(contentTypeUID).load(parent, attributeName, dbQuery);
47
47
  const info = {
@@ -1 +1 @@
1
- {"version":3,"file":"association.js","sources":["../../../../../server/src/services/builders/resolvers/association.ts"],"sourcesContent":["import { get, merge } from 'lodash/fp';\nimport { async, errors } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\n\nimport type { Context } from '../../types';\n\nconst { ApplicationError } = errors;\n\nexport default ({ strapi }: Context) => {\n const { service: getGraphQLService } = strapi.plugin('graphql');\n\n const { isMorphRelation, isMedia } = getGraphQLService('utils').attributes;\n const { transformArgs } = getGraphQLService('builders').utils;\n const { toEntityResponse, toEntityResponseCollection } = getGraphQLService('format').returnTypes;\n\n return {\n buildAssociationResolver({\n contentTypeUID,\n attributeName,\n }: {\n contentTypeUID: Internal.UID.ContentType;\n attributeName: string;\n }) {\n const contentType = strapi.getModel(contentTypeUID);\n const attribute: any = contentType.attributes[attributeName];\n\n if (!attribute) {\n throw new ApplicationError(\n `Failed to build an association resolver for ${contentTypeUID}::${attributeName}`\n );\n }\n\n const isMediaAttribute = isMedia(attribute);\n const isMorphAttribute = isMorphRelation(attribute);\n\n const targetUID = isMediaAttribute ? 'plugin::upload.file' : attribute.target;\n const isToMany = isMediaAttribute ? attribute.multiple : attribute.relation.endsWith('Many');\n\n const targetContentType = strapi.getModel(targetUID);\n\n return async (parent: any, args: any = {}, context: any = {}) => {\n const { auth } = context.state;\n\n const transformedArgs = transformArgs(args, {\n contentType: targetContentType,\n usePagination: true,\n });\n\n await strapi.contentAPI.validate.query(transformedArgs, targetContentType, {\n auth,\n });\n\n const sanitizedQuery = await strapi.contentAPI.sanitize.query(\n transformedArgs,\n targetContentType,\n {\n auth,\n }\n );\n\n const transformedQuery = strapi.get('query-params').transform(targetUID, sanitizedQuery);\n\n const defaultFilters = {\n where: {\n // Return the same draft and publish version as the parent\n publishedAt: { $notNull: 'publishedAt' in parent ? parent.publishedAt !== null : true },\n },\n };\n const dbQuery = merge(defaultFilters, transformedQuery);\n const data = await strapi.db?.query(contentTypeUID).load(parent, attributeName, dbQuery);\n\n const info = {\n args: sanitizedQuery,\n resourceUID: targetUID,\n };\n\n // If this a polymorphic association, it sanitizes & returns the raw data\n // Note: The value needs to be wrapped in a fake object that represents its parent\n // so that the sanitize util can work properly.\n if (isMorphAttribute) {\n // Helpers used for the data cleanup\n const wrapData = (dataToWrap: any) => ({ [attributeName]: dataToWrap });\n const sanitizeData = (dataToSanitize: any) => {\n return strapi.contentAPI.sanitize.output(dataToSanitize, contentType, { auth });\n };\n const unwrapData = get(attributeName);\n\n // Sanitizer definition\n const sanitizeMorphAttribute = async.pipe(wrapData, sanitizeData, unwrapData);\n\n return sanitizeMorphAttribute(data);\n }\n\n // If this is a to-many relation, it returns an object that\n // matches what the entity-response-collection's resolvers expect\n if (isToMany) {\n return toEntityResponseCollection(data, info);\n }\n\n // Else, it returns an object that matches\n // what the entity-response's resolvers expect\n return toEntityResponse(data, info);\n };\n },\n };\n};\n"],"names":["ApplicationError","errors","strapi","service","getGraphQLService","plugin","isMorphRelation","isMedia","attributes","transformArgs","utils","toEntityResponse","toEntityResponseCollection","returnTypes","buildAssociationResolver","contentTypeUID","attributeName","contentType","getModel","attribute","isMediaAttribute","isMorphAttribute","targetUID","target","isToMany","multiple","relation","endsWith","targetContentType","parent","args","context","auth","state","transformedArgs","usePagination","contentAPI","validate","query","sanitizedQuery","sanitize","transformedQuery","get","transform","defaultFilters","where","publishedAt","$notNull","dbQuery","merge","data","db","load","info","resourceUID","wrapData","dataToWrap","sanitizeData","dataToSanitize","output","unwrapData","sanitizeMorphAttribute","async","pipe"],"mappings":";;;;;AAMA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;AAE7B,2BAAe,CAAA,CAAC,EAAEC,MAAM,EAAW,GAAA;AACjC,IAAA,MAAM,EAAEC,OAASC,EAAAA,iBAAiB,EAAE,GAAGF,MAAAA,CAAOG,MAAM,CAAC,SAAA,CAAA;IAErD,MAAM,EAAEC,eAAe,EAAEC,OAAO,EAAE,GAAGH,iBAAAA,CAAkB,SAASI,UAAU;AAC1E,IAAA,MAAM,EAAEC,aAAa,EAAE,GAAGL,iBAAAA,CAAkB,YAAYM,KAAK;IAC7D,MAAM,EAAEC,gBAAgB,EAAEC,0BAA0B,EAAE,GAAGR,iBAAAA,CAAkB,UAAUS,WAAW;IAEhG,OAAO;AACLC,QAAAA,wBAAAA,CAAAA,CAAyB,EACvBC,cAAc,EACdC,aAAa,EAId,EAAA;YACC,MAAMC,WAAAA,GAAcf,MAAOgB,CAAAA,QAAQ,CAACH,cAAAA,CAAAA;AACpC,YAAA,MAAMI,SAAiBF,GAAAA,WAAAA,CAAYT,UAAU,CAACQ,aAAc,CAAA;AAE5D,YAAA,IAAI,CAACG,SAAW,EAAA;gBACd,MAAM,IAAInB,iBACR,CAAC,4CAA4C,EAAEe,cAAe,CAAA,EAAE,EAAEC,aAAAA,CAAc,CAAC,CAAA;AAErF;AAEA,YAAA,M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K;AACxF;AACF,iBAAA;gBACA,MAAME,OAAAA,GAAUC,SAAML,cAAgBH,EAAAA,gBAAAA,CAAAA;gBACtC,MAAMS,IAAAA,GAAO,MAAMhD,MAAOiD,CAAAA,EAAE,EAAEb,KAAMvB,CAAAA,cAAAA,CAAAA,CAAgBqC,IAAKvB,CAAAA,MAAAA,EAAQb,aAAegC,EAAAA,OAAAA,CAAAA;AAEhF,gBAAA,MAAMK,IAAO,GAAA;oBACXvB,IAAMS,EAAAA,cAAAA;oBACNe,WAAahC,EAAAA;AACf,iBAAA;;;;AAKA,gBAAA,IAAID,gBAAkB,EAAA;;oBAEpB,MAAMkC,QAAAA,GAAW,CAACC,UAAAA,IAAqB;AAAE,4BAAA,CAACxC,gBAAgBwC;yBAAW,CAAA;AACrE,oBAAA,MAAMC,eAAe,CAACC,cAAAA,GAAAA;wBACpB,OAAOxD,MAAAA,CAAOkC,UAAU,CAACI,QAAQ,CAACmB,MAAM,CAACD,gBAAgBzC,WAAa,EAAA;AAAEe,4BAAAA;AAAK,yBAAA,CAAA;AAC/E,qBAAA;AACA,oBAAA,MAAM4B,aAAalB,MAAI1B,CAAAA,aAAAA,CAAAA;;AAGvB,oBAAA,MAAM6C,sBAAyBC,GAAAA,WAAAA,CAAMC,IAAI,CAACR,UAAUE,YAAcG,EAAAA,UAAAA,CAAAA;AAElE,oBAAA,OAAOC,sBAAuBX,CAAAA,IAAAA,CAAAA;AAChC;;;AAIA,gBAAA,IAAI1B,QAAU,EAAA;AACZ,oBAAA,OAAOZ,2BAA2BsC,IAAMG,EAAAA,IAAAA,CAAAA;AAC1C;;;AAIA,gBAAA,OAAO1C,iBAAiBuC,IAAMG,EAAAA,IAAAA,CAAAA;AAChC,aAAA;AACF;AACF,KAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"association.js","sources":["../../../../../server/src/services/builders/resolvers/association.ts"],"sourcesContent":["import { get, merge } from 'lodash/fp';\nimport { async, contentTypes, errors } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\n\nimport type { Context } from '../../types';\n\nconst { ApplicationError } = errors;\n\nexport default ({ strapi }: Context) => {\n const { service: getGraphQLService } = strapi.plugin('graphql');\n\n const { isMorphRelation, isMedia } = getGraphQLService('utils').attributes;\n const { transformArgs } = getGraphQLService('builders').utils;\n const { toEntityResponse, toEntityResponseCollection } = getGraphQLService('format').returnTypes;\n\n return {\n buildAssociationResolver({\n contentTypeUID,\n attributeName,\n }: {\n contentTypeUID: Internal.UID.ContentType;\n attributeName: string;\n }) {\n const contentType = strapi.getModel(contentTypeUID);\n const attribute: any = contentType.attributes[attributeName];\n\n if (!attribute) {\n throw new ApplicationError(\n `Failed to build an association resolver for ${contentTypeUID}::${attributeName}`\n );\n }\n\n const isMediaAttribute = isMedia(attribute);\n const isMorphAttribute = isMorphRelation(attribute);\n\n const targetUID = isMediaAttribute ? 'plugin::upload.file' : attribute.target;\n const isToMany = isMediaAttribute ? attribute.multiple : attribute.relation.endsWith('Many');\n\n const targetContentType = strapi.getModel(targetUID);\n\n return async (parent: any, args: any = {}, context: any = {}) => {\n const { auth } = context.state;\n\n const transformedArgs = transformArgs(args, {\n contentType: targetContentType,\n usePagination: true,\n });\n\n await strapi.contentAPI.validate.query(transformedArgs, targetContentType, {\n auth,\n });\n\n const sanitizedQuery = await strapi.contentAPI.sanitize.query(\n transformedArgs,\n targetContentType,\n {\n auth,\n }\n );\n const transformedQuery = strapi.get('query-params').transform(targetUID, sanitizedQuery);\n\n const isTargetDraftAndPublishContentType =\n contentTypes.hasDraftAndPublish(targetContentType);\n const defaultFilters = isTargetDraftAndPublishContentType\n ? {\n where: {\n publishedAt: {\n $notNull: context.rootQueryArgs?.status\n ? // Filter by the same status as the root query if the argument is present\n context.rootQueryArgs?.status === 'published'\n : // Otherwise fallback to the published version\n true,\n },\n },\n }\n : {};\n\n const dbQuery = merge(defaultFilters, transformedQuery);\n const data = await strapi.db?.query(contentTypeUID).load(parent, attributeName, dbQuery);\n\n const info = {\n args: sanitizedQuery,\n resourceUID: targetUID,\n };\n\n // If this a polymorphic association, it sanitizes & returns the raw data\n // Note: The value needs to be wrapped in a fake object that represents its parent\n // so that the sanitize util can work properly.\n if (isMorphAttribute) {\n // Helpers used for the data cleanup\n const wrapData = (dataToWrap: any) => ({ [attributeName]: dataToWrap });\n const sanitizeData = (dataToSanitize: any) => {\n return strapi.contentAPI.sanitize.output(dataToSanitize, contentType, { auth });\n };\n const unwrapData = get(attributeName);\n\n // Sanitizer definition\n const sanitizeMorphAttribute = async.pipe(wrapData, sanitizeData, unwrapData);\n\n return sanitizeMorphAttribute(data);\n }\n\n // If this is a to-many relation, it returns an object that\n // matches what the entity-response-collection's resolvers expect\n if (isToMany) {\n return toEntityResponseCollection(data, info);\n }\n\n // Else, it returns an object that matches\n // what the entity-response's resolvers expect\n return toEntityResponse(data, info);\n };\n },\n };\n};\n"],"names":["ApplicationError","errors","strapi","service","getGraphQLService","plugin","isMorphRelation","isMedia","attributes","transformArgs","utils","toEntityResponse","toEntityResponseCollection","returnTypes","buildAssociationResolver","contentTypeUID","attributeName","contentType","getModel","attribute","isMediaAttribute","isMorphAttribute","targetUID","target","isToMany","multiple","relation","endsWith","targetContentType","parent","args","context","auth","state","transformedArgs","usePagination","contentAPI","validate","query","sanitizedQuery","sanitize","transformedQuery","get","transform","isTargetDraftAndPublishContentType","contentTypes","hasDraftAndPublish","defaultFilters","where","publishedAt","$notNull","rootQueryArgs","status","dbQuery","merge","data","db","load","info","resourceUID","wrapData","dataToWrap","sanitizeData","dataToSanitize","output","unwrapData","sanitizeMorphAttribute","async","pipe"],"mappings":";;;;;AAMA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;AAE7B,2BAAe,CAAA,CAAC,EAAEC,MAAM,EAAW,GAAA;AACjC,IAAA,MAAM,EAAEC,OAASC,EAAAA,iBAAiB,EAAE,GAAGF,MAAAA,CAAOG,MAAM,CAAC,SAAA,CAAA;IAErD,MAAM,EAAEC,eAAe,EAAEC,OAAO,EAAE,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AAAA,CAAOkC,UAAU,CAACI,QAAQ,CAACwB,MAAM,CAACD,gBAAgB9C,WAAa,EAAA;AAAEe,4BAAAA;AAAK,yBAAA,CAAA;AAC/E,qBAAA;AACA,oBAAA,MAAMiC,aAAavB,MAAI1B,CAAAA,aAAAA,CAAAA;;AAGvB,oBAAA,MAAMkD,sBAAyBC,GAAAA,WAAAA,CAAMC,IAAI,CAACR,UAAUE,YAAcG,EAAAA,UAAAA,CAAAA;AAElE,oBAAA,OAAOC,sBAAuBX,CAAAA,IAAAA,CAAAA;AAChC;;;AAIA,gBAAA,IAAI/B,QAAU,EAAA;AACZ,oBAAA,OAAOZ,2BAA2B2C,IAAMG,EAAAA,IAAAA,CAAAA;AAC1C;;;AAIA,gBAAA,OAAO/C,iBAAiB4C,IAAMG,EAAAA,IAAAA,CAAAA;AAChC,aAAA;AACF;AACF,KAAA;AACF,CAAA;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { merge, get } from 'lodash/fp';
2
- import { async, errors } from '@strapi/utils';
2
+ import { contentTypes, async, errors } from '@strapi/utils';
3
3
 
4
4
  const { ApplicationError } = errors;
5
5
  var associationResolvers = (({ strapi })=>{
@@ -32,14 +32,14 @@ var associationResolvers = (({ strapi })=>{
32
32
  auth
33
33
  });
34
34
  const transformedQuery = strapi.get('query-params').transform(targetUID, sanitizedQuery);
35
- const defaultFilters = {
35
+ const isTargetDraftAndPublishContentType = contentTypes.hasDraftAndPublish(targetContentType);
36
+ const defaultFilters = isTargetDraftAndPublishContentType ? {
36
37
  where: {
37
- // Return the same draft and publish version as the parent
38
38
  publishedAt: {
39
- $notNull: 'publishedAt' in parent ? parent.publishedAt !== null : true
39
+ $notNull: context.rootQueryArgs?.status ? context.rootQueryArgs?.status === 'published' : true
40
40
  }
41
41
  }
42
- };
42
+ } : {};
43
43
  const dbQuery = merge(defaultFilters, transformedQuery);
44
44
  const data = await strapi.db?.query(contentTypeUID).load(parent, attributeName, dbQuery);
45
45
  const info = {
@@ -1 +1 @@
1
- {"version":3,"file":"association.mjs","sources":["../../../../../server/src/services/builders/resolvers/association.ts"],"sourcesContent":["import { get, merge } from 'lodash/fp';\nimport { async, errors } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\n\nimport type { Context } from '../../types';\n\nconst { ApplicationError } = errors;\n\nexport default ({ strapi }: Context) => {\n const { service: getGraphQLService } = strapi.plugin('graphql');\n\n const { isMorphRelation, isMedia } = getGraphQLService('utils').attributes;\n const { transformArgs } = getGraphQLService('builders').utils;\n const { toEntityResponse, toEntityResponseCollection } = getGraphQLService('format').returnTypes;\n\n return {\n buildAssociationResolver({\n contentTypeUID,\n attributeName,\n }: {\n contentTypeUID: Internal.UID.ContentType;\n attributeName: string;\n }) {\n const contentType = strapi.getModel(contentTypeUID);\n const attribute: any = contentType.attributes[attributeName];\n\n if (!attribute) {\n throw new ApplicationError(\n `Failed to build an association resolver for ${contentTypeUID}::${attributeName}`\n );\n }\n\n const isMediaAttribute = isMedia(attribute);\n const isMorphAttribute = isMorphRelation(attribute);\n\n const targetUID = isMediaAttribute ? 'plugin::upload.file' : attribute.target;\n const isToMany = isMediaAttribute ? attribute.multiple : attribute.relation.endsWith('Many');\n\n const targetContentType = strapi.getModel(targetUID);\n\n return async (parent: any, args: any = {}, context: any = {}) => {\n const { auth } = context.state;\n\n const transformedArgs = transformArgs(args, {\n contentType: targetContentType,\n usePagination: true,\n });\n\n await strapi.contentAPI.validate.query(transformedArgs, targetContentType, {\n auth,\n });\n\n const sanitizedQuery = await strapi.contentAPI.sanitize.query(\n transformedArgs,\n targetContentType,\n {\n auth,\n }\n );\n\n const transformedQuery = strapi.get('query-params').transform(targetUID, sanitizedQuery);\n\n const defaultFilters = {\n where: {\n // Return the same draft and publish version as the parent\n publishedAt: { $notNull: 'publishedAt' in parent ? parent.publishedAt !== null : true },\n },\n };\n const dbQuery = merge(defaultFilters, transformedQuery);\n const data = await strapi.db?.query(contentTypeUID).load(parent, attributeName, dbQuery);\n\n const info = {\n args: sanitizedQuery,\n resourceUID: targetUID,\n };\n\n // If this a polymorphic association, it sanitizes & returns the raw data\n // Note: The value needs to be wrapped in a fake object that represents its parent\n // so that the sanitize util can work properly.\n if (isMorphAttribute) {\n // Helpers used for the data cleanup\n const wrapData = (dataToWrap: any) => ({ [attributeName]: dataToWrap });\n const sanitizeData = (dataToSanitize: any) => {\n return strapi.contentAPI.sanitize.output(dataToSanitize, contentType, { auth });\n };\n const unwrapData = get(attributeName);\n\n // Sanitizer definition\n const sanitizeMorphAttribute = async.pipe(wrapData, sanitizeData, unwrapData);\n\n return sanitizeMorphAttribute(data);\n }\n\n // If this is a to-many relation, it returns an object that\n // matches what the entity-response-collection's resolvers expect\n if (isToMany) {\n return toEntityResponseCollection(data, info);\n }\n\n // Else, it returns an object that matches\n // what the entity-response's resolvers expect\n return toEntityResponse(data, info);\n };\n },\n };\n};\n"],"names":["ApplicationError","errors","strapi","service","getGraphQLService","plugin","isMorphRelation","isMedia","attributes","transformArgs","utils","toEntityResponse","toEntityResponseCollection","returnTypes","buildAssociationResolver","contentTypeUID","attributeName","contentType","getModel","attribute","isMediaAttribute","isMorphAttribute","targetUID","target","isToMany","multiple","relation","endsWith","targetContentType","parent","args","context","auth","state","transformedArgs","usePagination","contentAPI","validate","query","sanitizedQuery","sanitize","transformedQuery","get","transform","defaultFilters","where","publishedAt","$notNull","dbQuery","merge","data","db","load","info","resourceUID","wrapData","dataToWrap","sanitizeData","dataToSanitize","output","unwrapData","sanitizeMorphAttribute","async","pipe"],"mappings":";;;AAMA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,MAAAA;AAE7B,2BAAe,CAAA,CAAC,EAAEC,MAAM,EAAW,GAAA;AACjC,IAAA,MAAM,EAAEC,OAASC,EAAAA,iBAAiB,EAAE,GAAGF,MAAAA,CAAOG,MAAM,CAAC,SAAA,CAAA;IAErD,MAAM,EAAEC,eAAe,EAAEC,OAAO,EAAE,GAAGH,iBAAAA,CAAkB,SAASI,UAAU;AAC1E,IAAA,MAAM,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AAA,aAAAA,CAAAA;;AAGvB,oBAAA,MAAM6C,sBAAyBC,GAAAA,KAAAA,CAAMC,IAAI,CAACR,UAAUE,YAAcG,EAAAA,UAAAA,CAAAA;AAElE,oBAAA,OAAOC,sBAAuBX,CAAAA,IAAAA,CAAAA;AAChC;;;AAIA,gBAAA,IAAI1B,QAAU,EAAA;AACZ,oBAAA,OAAOZ,2BAA2BsC,IAAMG,EAAAA,IAAAA,CAAAA;AAC1C;;;AAIA,gBAAA,OAAO1C,iBAAiBuC,IAAMG,EAAAA,IAAAA,CAAAA;AAChC,aAAA;AACF;AACF,KAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"association.mjs","sources":["../../../../../server/src/services/builders/resolvers/association.ts"],"sourcesContent":["import { get, merge } from 'lodash/fp';\nimport { async, contentTypes, errors } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\n\nimport type { Context } from '../../types';\n\nconst { ApplicationError } = errors;\n\nexport default ({ strapi }: Context) => {\n const { service: getGraphQLService } = strapi.plugin('graphql');\n\n const { isMorphRelation, isMedia } = getGraphQLService('utils').attributes;\n const { transformArgs } = getGraphQLService('builders').utils;\n const { toEntityResponse, toEntityResponseCollection } = getGraphQLService('format').returnTypes;\n\n return {\n buildAssociationResolver({\n contentTypeUID,\n attributeName,\n }: {\n contentTypeUID: Internal.UID.ContentType;\n attributeName: string;\n }) {\n const contentType = strapi.getModel(contentTypeUID);\n const attribute: any = contentType.attributes[attributeName];\n\n if (!attribute) {\n throw new ApplicationError(\n `Failed to build an association resolver for ${contentTypeUID}::${attributeName}`\n );\n }\n\n const isMediaAttribute = isMedia(attribute);\n const isMorphAttribute = isMorphRelation(attribute);\n\n const targetUID = isMediaAttribute ? 'plugin::upload.file' : attribute.target;\n const isToMany = isMediaAttribute ? attribute.multiple : attribute.relation.endsWith('Many');\n\n const targetContentType = strapi.getModel(targetUID);\n\n return async (parent: any, args: any = {}, context: any = {}) => {\n const { auth } = context.state;\n\n const transformedArgs = transformArgs(args, {\n contentType: targetContentType,\n usePagination: true,\n });\n\n await strapi.contentAPI.validate.query(transformedArgs, targetContentType, {\n auth,\n });\n\n const sanitizedQuery = await strapi.contentAPI.sanitize.query(\n transformedArgs,\n targetContentType,\n {\n auth,\n }\n );\n const transformedQuery = strapi.get('query-params').transform(targetUID, sanitizedQuery);\n\n const isTargetDraftAndPublishContentType =\n contentTypes.hasDraftAndPublish(targetContentType);\n const defaultFilters = isTargetDraftAndPublishContentType\n ? {\n where: {\n publishedAt: {\n $notNull: context.rootQueryArgs?.status\n ? // Filter by the same status as the root query if the argument is present\n context.rootQueryArgs?.status === 'published'\n : // Otherwise fallback to the published version\n true,\n },\n },\n }\n : {};\n\n const dbQuery = merge(defaultFilters, transformedQuery);\n const data = await strapi.db?.query(contentTypeUID).load(parent, attributeName, dbQuery);\n\n const info = {\n args: sanitizedQuery,\n resourceUID: targetUID,\n };\n\n // If this a polymorphic association, it sanitizes & returns the raw data\n // Note: The value needs to be wrapped in a fake object that represents its parent\n // so that the sanitize util can work properly.\n if (isMorphAttribute) {\n // Helpers used for the data cleanup\n const wrapData = (dataToWrap: any) => ({ [attributeName]: dataToWrap });\n const sanitizeData = (dataToSanitize: any) => {\n return strapi.contentAPI.sanitize.output(dataToSanitize, contentType, { auth });\n };\n const unwrapData = get(attributeName);\n\n // Sanitizer definition\n const sanitizeMorphAttribute = async.pipe(wrapData, sanitizeData, unwrapData);\n\n return sanitizeMorphAttribute(data);\n }\n\n // If this is a to-many relation, it returns an object that\n // matches what the entity-response-collection's resolvers expect\n if (isToMany) {\n return toEntityResponseCollection(data, info);\n }\n\n // Else, it returns an object that matches\n // what the entity-response's resolvers expect\n return toEntityResponse(data, info);\n };\n },\n };\n};\n"],"names":["ApplicationError","errors","strapi","service","getGraphQLService","plugin","isMorphRelation","isMedia","attributes","transformArgs","utils","toEntityResponse","toEntityResponseCollection","returnTypes","buildAssociationResolver","contentTypeUID","attributeName","contentType","getModel","attribute","isMediaAttribute","isMorphAttribute","targetUID","target","isToMany","multiple","relation","endsWith","targetContentType","parent","args","context","auth","state","transformedArgs","usePagination","contentAPI","validate","query","sanitizedQuery","sanitize","transformedQuery","get","transform","isTargetDraftAndPublishContentType","contentTypes","hasDraftAndPublish","defaultFilters","where","publishedAt","$notNull","rootQueryArgs","status","dbQuery","merge","data","db","load","info","resourceUID","wrapData","dataToWrap","sanitizeData","dataToSanitize","output","unwrapData","sanitizeMorphAttribute","async","pipe"],"mappings":";;;AAMA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,MAAAA;AAE7B,2BAAe,CAAA,CAAC,EAAEC,MAAM,EAAW,GAAA;AACjC,IAAA,MAAM,EAAEC,OAASC,EAAAA,iBAAiB,EAAE,GAAGF,MAAAA,CAAOG,MAAM,CAAC,SAAA,CAAA;IAErD,MAAM,EAAEC,eAAe,EAAEC,OAAO,EAAE,GAAGH,iBAAAA,CAAkB,SAASI,UAAU;AAC1E,IAAA,MAAM,EAAEC,aAAa,EAAE,GAAGL,iBAAAA,CAAkB,YAAYM,KAAK;IAC7D,MAAM,EAAEC,gBAAgB,EAAEC,0BAA0B,EAAE,GAAGR,iBAAAA,CAAkB,UAAUS,WAAW;IAEhG,OAAO;AACLC,QAAAA,wBAAAA,CAAAA,CAAyB,EACvBC,cAAc,EACdC,aAAa,EAId,EAAA;YACC,MAAMC,WAAAA,GAAcf,MAAOgB,CAAAA,QAAQ,CAACH,cAAAA,CAAAA;AACpC,YAAA,MAAMI,SAAiBF,GAAAA,WAAAA,CAAYT,UAAU,CAACQ,aAAc,CAAA;AAE5D,YAAA,IAAI,CAACG,SAAW,EAAA;gBACd,MAAM,IAAInB,iBACR,CAAC,4CAA4C,EAAEe,cAAe,CAAA,EAAE,EAAEC,aAAAA,CAAc,CAAC,CAAA;AAErF;AAEA,YAAA,MAAMI,mBAAmBb,OAAQY,CAAAA,SAAAA,CAAAA;AACjC,YAAA,MAAME,mBAAmBf,eAAgBa,CAAAA,SAAAA,CAAAA;AAEzC,YAAA,MAAMG,SAA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L,MAAMC,OAAAA,GAAUC,MAAMP,cAAgBN,EAAAA,gBAAAA,CAAAA;gBACtC,MAAMc,IAAAA,GAAO,MAAMrD,MAAOsD,CAAAA,EAAE,EAAElB,KAAMvB,CAAAA,cAAAA,CAAAA,CAAgB0C,IAAK5B,CAAAA,MAAAA,EAAQb,aAAeqC,EAAAA,OAAAA,CAAAA;AAEhF,gBAAA,MAAMK,IAAO,GAAA;oBACX5B,IAAMS,EAAAA,cAAAA;oBACNoB,WAAarC,EAAAA;AACf,iBAAA;;;;AAKA,gBAAA,IAAID,gBAAkB,EAAA;;oBAEpB,MAAMuC,QAAAA,GAAW,CAACC,UAAAA,IAAqB;AAAE,4BAAA,CAAC7C,gBAAgB6C;yBAAW,CAAA;AACrE,oBAAA,MAAMC,eAAe,CAACC,cAAAA,GAAAA;wBACpB,OAAO7D,MAAAA,CAAOkC,UAAU,CAACI,QAAQ,CAACwB,MAAM,CAACD,gBAAgB9C,WAAa,EAAA;AAAEe,4BAAAA;AAAK,yBAAA,CAAA;AAC/E,qBAAA;AACA,oBAAA,MAAMiC,aAAavB,GAAI1B,CAAAA,aAAAA,CAAAA;;AAGvB,oBAAA,MAAMkD,sBAAyBC,GAAAA,KAAAA,CAAMC,IAAI,CAACR,UAAUE,YAAcG,EAAAA,UAAAA,CAAAA;AAElE,oBAAA,OAAOC,sBAAuBX,CAAAA,IAAAA,CAAAA;AAChC;;;AAIA,gBAAA,IAAI/B,QAAU,EAAA;AACZ,oBAAA,OAAOZ,2BAA2B2C,IAAMG,EAAAA,IAAAA,CAAAA;AAC1C;;;AAIA,gBAAA,OAAO/C,iBAAiB4C,IAAMG,EAAAA,IAAAA,CAAAA;AAChC,aAAA;AACF;AACF,KAAA;AACF,CAAA;;;;"}
@@ -1,7 +1,13 @@
1
+ /// <reference types="koa-session" />
1
2
  import { type ApolloServerPlugin } from '@apollo/server';
2
3
  import type { Core } from '@strapi/types';
3
- export declare const determineLandingPage: (strapi: Core.Strapi) => ApolloServerPlugin<import("@apollo/server").BaseContext>;
4
+ import type { BaseContext } from 'koa';
5
+ type StrapiGraphQLContext = BaseContext & {
6
+ rootQueryArgs?: Record<string, unknown>;
7
+ };
8
+ export declare const determineLandingPage: (strapi: Core.Strapi) => ApolloServerPlugin<StrapiGraphQLContext>;
4
9
  export declare function bootstrap({ strapi }: {
5
10
  strapi: Core.Strapi;
6
11
  }): Promise<void>;
12
+ export {};
7
13
  //# sourceMappingURL=bootstrap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../../server/src/bootstrap.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,kBAAkB,EAA4B,MAAM,gBAAgB,CAAC;AAUjG,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAW1C,eAAO,MAAM,oBAAoB,WAAY,KAAK,MAAM,6DA8EvD,CAAC;AAEF,wBAAsB,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;CAAE,iBAmIlE"}
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../../server/src/bootstrap.ts"],"names":[],"mappings":";AACA,OAAO,EAAgB,KAAK,kBAAkB,EAA4B,MAAM,gBAAgB,CAAC;AAUjG,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAA8C,MAAM,KAAK,CAAC;AAUnF,KAAK,oBAAoB,GAAG,WAAW,GAAG;IACxC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,CAAC;AAEF,eAAO,MAAM,oBAAoB,WACvB,KAAK,MAAM,KAClB,mBAAmB,oBAAoB,CA8EzC,CAAC;AAEF,wBAAsB,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;CAAE,iBA4JlE"}
@@ -1 +1 @@
1
- {"version":3,"file":"association.d.ts","sourceRoot":"","sources":["../../../../../../server/src/services/builders/resolvers/association.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;qCAIf,OAAO;iEAW5B;QACD,cAAc,EAAE,SAAS,GAAG,CAAC,WAAW,CAAC;QACzC,aAAa,EAAE,MAAM,CAAC;KACvB,YAkBuB,GAAG,SAAQ,GAAG,YAAgB,GAAG;;AAhC7D,wBAiGE"}
1
+ {"version":3,"file":"association.d.ts","sourceRoot":"","sources":["../../../../../../server/src/services/builders/resolvers/association.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;qCAIf,OAAO;iEAW5B;QACD,cAAc,EAAE,SAAS,GAAG,CAAC,WAAW,CAAC;QACzC,aAAa,EAAE,MAAM,CAAC;KACvB,YAkBuB,GAAG,SAAQ,GAAG,YAAgB,GAAG;;AAhC7D,wBA0GE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-graphql",
3
- "version": "5.17.0-beta.0",
3
+ "version": "5.18.0",
4
4
  "description": "Adds GraphQL endpoint with default API methods.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -57,9 +57,9 @@
57
57
  "@graphql-tools/schema": "10.0.3",
58
58
  "@graphql-tools/utils": "^10.1.3",
59
59
  "@koa/cors": "5.0.0",
60
- "@strapi/design-system": "2.0.0-rc.26",
61
- "@strapi/icons": "2.0.0-rc.26",
62
- "@strapi/utils": "5.17.0-beta.0",
60
+ "@strapi/design-system": "2.0.0-rc.28",
61
+ "@strapi/icons": "2.0.0-rc.28",
62
+ "@strapi/utils": "5.18.0",
63
63
  "graphql": "^16.8.1",
64
64
  "graphql-depth-limit": "^1.1.0",
65
65
  "graphql-playground-middleware-koa": "^1.6.21",
@@ -71,19 +71,19 @@
71
71
  "pluralize": "8.0.0"
72
72
  },
73
73
  "devDependencies": {
74
- "@strapi/strapi": "5.17.0-beta.0",
75
- "@strapi/types": "5.17.0-beta.0",
74
+ "@strapi/strapi": "5.18.0",
75
+ "@strapi/types": "5.18.0",
76
76
  "@types/graphql-depth-limit": "1.1.5",
77
77
  "@types/koa-bodyparser": "4.3.12",
78
78
  "@types/koa__cors": "5.0.0",
79
79
  "cross-env": "^7.0.3",
80
- "eslint-config-custom": "5.17.0-beta.0",
80
+ "eslint-config-custom": "5.18.0",
81
81
  "koa": "2.16.1",
82
82
  "react": "18.3.1",
83
83
  "react-dom": "18.3.1",
84
84
  "react-router-dom": "6.22.3",
85
85
  "styled-components": "6.1.8",
86
- "tsconfig": "5.17.0-beta.0",
86
+ "tsconfig": "5.18.0",
87
87
  "typescript": "5.4.4"
88
88
  },
89
89
  "peerDependencies": {