@strapi/plugin-graphql 5.45.1 → 5.46.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/server/bootstrap.js +7 -6
- package/dist/server/bootstrap.js.map +1 -1
- package/dist/server/bootstrap.mjs +7 -6
- package/dist/server/bootstrap.mjs.map +1 -1
- package/dist/server/services/builders/resolvers/association.js +9 -3
- package/dist/server/services/builders/resolvers/association.js.map +1 -1
- package/dist/server/services/builders/resolvers/association.mjs +9 -3
- package/dist/server/services/builders/resolvers/association.mjs.map +1 -1
- package/dist/server/services/builders/utils.js +2 -2
- package/dist/server/services/builders/utils.js.map +1 -1
- package/dist/server/services/builders/utils.mjs +2 -2
- package/dist/server/services/builders/utils.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts +1 -1
- package/dist/server/src/bootstrap.d.ts.map +1 -1
- package/dist/server/src/services/builders/resolvers/association.d.ts +1 -1
- package/dist/server/src/services/builders/resolvers/association.d.ts.map +1 -1
- package/dist/server/src/services/builders/resolvers/index.d.ts +1 -1
- package/package.json +6 -6
package/dist/server/bootstrap.js
CHANGED
|
@@ -100,13 +100,14 @@ async function bootstrap({ strapi }) {
|
|
|
100
100
|
return {
|
|
101
101
|
willResolveField ({ source, args, contextValue, info }) {
|
|
102
102
|
if (!source && info.operation.operation === 'query') {
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
// Key args per root field (alias)
|
|
104
|
+
if (!contextValue.rootQueryArgsByPath) {
|
|
105
|
+
contextValue.rootQueryArgsByPath = new Map();
|
|
106
|
+
}
|
|
107
|
+
contextValue.rootQueryArgsByPath.set(info.path.key, {
|
|
107
108
|
...args,
|
|
108
|
-
_originField: fieldName
|
|
109
|
-
};
|
|
109
|
+
_originField: info.fieldName
|
|
110
|
+
});
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
};
|
|
@@ -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 { Options } from '@koa/cors';\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 // Track which query field set the rootQueryArgs\n const fieldName = info.fieldName;\n // Set rootQueryArgs with the field name that originated it\n contextValue.rootQueryArgs = {\n ...args,\n _originField: fieldName, // Track which field set this\n };\n }\n },\n };\n },\n };\n },\n };\n\n type CustomOptions = {\n cors?: boolean | Options;\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: undefined,\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 (serverConfig.cors === false) {\n // Explicitly disabled - don't add middleware\n } else if (serverConfig.cors === undefined || serverConfig.cors === true) {\n // enable with defaults (backwards compatible)\n handler.push(cors());\n } else {\n // Custom options object\n handler.push(cors(serverConfig.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","fieldName","rootQueryArgs","_originField","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":";;;;;;;;;;;AAiBA,MAAMA,KAAAA,GAAQC,YAAAA,CAAU,CAACC,CAAAA,EAAGC,CAAAA,GAAAA;IAC1B,IAAIC,UAAAA,CAAQF,CAAAA,CAAAA,IAAME,UAAAA,CAAQD,CAAAA,CAAAA,EAAI;QAC5B,OAAOD,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KAAK5C;QACpB7B,MAAAA,CAAOE,MAAM,CAAC,SAAA,CAAA,CAAWE,OAAO,CAAC,SAASS,UAAU,CAAC6D,SAAS,EAAA;QAC9DT,GAAAA,CAAIM,OAAO,CAACI,MAAM,CAACC,MAAM,EAAEC,QAAAA,CAAS;;AAGtC,QAAA,IAAIP,mBAAAA,EAAqB;YACvB,OAAOJ,IAAAA,EAAAA;AACT,QAAA;AAEA,QAAA,OAAOlE,MAAAA,CAAO8E,IAAI,CAACC,YAAY,CAACd,GAAAA,EAAKC,IAAAA,CAAAA;AACvC,IAAA,CAAA,CAAA;;IAGAL,OAAAA,CAAQC,IAAI,CACVkB,iBAAAA,CAA0DzB,QAAAA,EAAQ;;AAEhE0B,QAAAA,OAAAA,EAAS,OAAO,EAAEhB,GAAG,EAAE,IAAM;AAC3BE,gBAAAA,KAAAA,EAAOF,IAAIE,KAAK;gBAChBe,UAAAA,EAAYjB;aACd;AACF,KAAA,CAAA,CAAA;;IAIFjE,MAAAA,CAAOuD,MAAM,CAAC4B,MAAM,CAAC;AACnB,QAAA;YACEX,MAAAA,EAAQ,KAAA;AACR3C,YAAAA,IAAAA;AACAgC,YAAAA,OAAAA;YACA5D,MAAAA,EAAQ;gBACN6E,IAAAA,EAAM;AACR;AACF;AACD,KAAA,CAAA;;;;AAKD9E,IAAAA,MAAAA,CAAOE,MAAM,CAAC,SAAA,CAAA,CAAWkF,OAAO,GAAG,UAAA;AACjC,QAAA,MAAM7B,SAAO8B,IAAI,EAAA;AACnB,IAAA,CAAA;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 { Options } from '@koa/cors';\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 rootQueryArgsByPath?: Map<string | number, 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 // Key args per root field (alias)\n if (!contextValue.rootQueryArgsByPath) {\n contextValue.rootQueryArgsByPath = new Map();\n }\n contextValue.rootQueryArgsByPath.set(info.path.key, {\n ...args,\n _originField: info.fieldName,\n });\n }\n },\n };\n },\n };\n },\n };\n\n type CustomOptions = {\n cors?: boolean | Options;\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: undefined,\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 (serverConfig.cors === false) {\n // Explicitly disabled - don't add middleware\n } else if (serverConfig.cors === undefined || serverConfig.cors === true) {\n // enable with defaults (backwards compatible)\n handler.push(cors());\n } else {\n // Custom options object\n handler.push(cors(serverConfig.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","rootQueryArgsByPath","Map","set","key","_originField","fieldName","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":";;;;;;;;;;;AAiBA,MAAMA,KAAAA,GAAQC,YAAAA,CAAU,CAACC,CAAAA,EAAGC,CAAAA,GAAAA;IAC1B,IAAIC,UAAAA,CAAQF,CAAAA,CAAAA,IAAME,UAAAA,CAAQD,CAAAA,CAAAA,EAAI;QAC5B,OAAOD,CAAAA,CAAEG,MAAM,CAACF,CAAAA,CAAAA;AAClB,IAAA;AACF,CAAA,CAAA;AAMO,MAAMG,uBAAuB,CAClCC,MAAAA,GAAAA;AAEA,IAAA,MAAM,EAAEC,MAAM,EAAE,GAAGD,MAAAA,CAAOE,MAAM,CAAC,SAAA,CAAA;AACjC,IAAA,MAA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,UAAU,CAACgE,SAAS,EAAA;QAC9DT,GAAAA,CAAIM,OAAO,CAACI,MAAM,CAACC,MAAM,EAAEC,QAAAA,CAAS;;AAGtC,QAAA,IAAIP,mBAAAA,EAAqB;YACvB,OAAOJ,IAAAA,EAAAA;AACT,QAAA;AAEA,QAAA,OAAOrE,MAAAA,CAAOiF,IAAI,CAACC,YAAY,CAACd,GAAAA,EAAKC,IAAAA,CAAAA;AACvC,IAAA,CAAA,CAAA;;IAGAL,OAAAA,CAAQC,IAAI,CACVkB,iBAAAA,CAA0DzB,QAAAA,EAAQ;;AAEhE0B,QAAAA,OAAAA,EAAS,OAAO,EAAEhB,GAAG,EAAE,IAAM;AAC3BE,gBAAAA,KAAAA,EAAOF,IAAIE,KAAK;gBAChBe,UAAAA,EAAYjB;aACd;AACF,KAAA,CAAA,CAAA;;IAIFpE,MAAAA,CAAO0D,MAAM,CAAC4B,MAAM,CAAC;AACnB,QAAA;YACEX,MAAAA,EAAQ,KAAA;AACR9C,YAAAA,IAAAA;AACAmC,YAAAA,OAAAA;YACA/D,MAAAA,EAAQ;gBACNgF,IAAAA,EAAM;AACR;AACF;AACD,KAAA,CAAA;;;;AAKDjF,IAAAA,MAAAA,CAAOE,MAAM,CAAC,SAAA,CAAA,CAAWqF,OAAO,GAAG,UAAA;AACjC,QAAA,MAAM7B,SAAO8B,IAAI,EAAA;AACnB,IAAA,CAAA;AACF;;;;;"}
|
|
@@ -98,13 +98,14 @@ async function bootstrap({ strapi }) {
|
|
|
98
98
|
return {
|
|
99
99
|
willResolveField ({ source, args, contextValue, info }) {
|
|
100
100
|
if (!source && info.operation.operation === 'query') {
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
// Key args per root field (alias)
|
|
102
|
+
if (!contextValue.rootQueryArgsByPath) {
|
|
103
|
+
contextValue.rootQueryArgsByPath = new Map();
|
|
104
|
+
}
|
|
105
|
+
contextValue.rootQueryArgsByPath.set(info.path.key, {
|
|
105
106
|
...args,
|
|
106
|
-
_originField: fieldName
|
|
107
|
-
};
|
|
107
|
+
_originField: info.fieldName
|
|
108
|
+
});
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
};
|
|
@@ -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 { Options } from '@koa/cors';\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 // Track which query field set the rootQueryArgs\n const fieldName = info.fieldName;\n // Set rootQueryArgs with the field name that originated it\n contextValue.rootQueryArgs = {\n ...args,\n _originField: fieldName, // Track which field set this\n };\n }\n },\n };\n },\n };\n },\n };\n\n type CustomOptions = {\n cors?: boolean | Options;\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: undefined,\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 (serverConfig.cors === false) {\n // Explicitly disabled - don't add middleware\n } else if (serverConfig.cors === undefined || serverConfig.cors === true) {\n // enable with defaults (backwards compatible)\n handler.push(cors());\n } else {\n // Custom options object\n handler.push(cors(serverConfig.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","fieldName","rootQueryArgs","_originField","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":";;;;;;;;;AAi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AAAA,EAAM;;gBAEJ+B,IAAAA,EAAM;AACR;AACF,SAAA;AAEA,QAAA,MAAMC,mBAAAA,GACJL,GAAAA,CAAIM,OAAO,CAACC,MAAM,KAAK,KAAA,IACvBP,GAAAA,CAAIM,OAAO,CAACE,GAAG,KAAK5C;QACpB7B,MAAAA,CAAOE,MAAM,CAAC,SAAA,CAAA,CAAWE,OAAO,CAAC,SAASS,UAAU,CAAC6D,SAAS,EAAA;QAC9DT,GAAAA,CAAIM,OAAO,CAACI,MAAM,CAACC,MAAM,EAAEC,QAAAA,CAAS;;AAGtC,QAAA,IAAIP,mBAAAA,EAAqB;YACvB,OAAOJ,IAAAA,EAAAA;AACT,QAAA;AAEA,QAAA,OAAOlE,MAAAA,CAAO8E,IAAI,CAACC,YAAY,CAACd,GAAAA,EAAKC,IAAAA,CAAAA;AACvC,IAAA,CAAA,CAAA;;IAGAL,OAAAA,CAAQC,IAAI,CACVkB,aAAAA,CAA0DzB,MAAAA,EAAQ;;AAEhE0B,QAAAA,OAAAA,EAAS,OAAO,EAAEhB,GAAG,EAAE,IAAM;AAC3BE,gBAAAA,KAAAA,EAAOF,IAAIE,KAAK;gBAChBe,UAAAA,EAAYjB;aACd;AACF,KAAA,CAAA,CAAA;;IAIFjE,MAAAA,CAAOuD,MAAM,CAAC4B,MAAM,CAAC;AACnB,QAAA;YACEX,MAAAA,EAAQ,KAAA;AACR3C,YAAAA,IAAAA;AACAgC,YAAAA,OAAAA;YACA5D,MAAAA,EAAQ;gBACN6E,IAAAA,EAAM;AACR;AACF;AACD,KAAA,CAAA;;;;AAKD9E,IAAAA,MAAAA,CAAOE,MAAM,CAAC,SAAA,CAAA,CAAWkF,OAAO,GAAG,UAAA;AACjC,QAAA,MAAM7B,OAAO8B,IAAI,EAAA;AACnB,IAAA,CAAA;AACF;;;;"}
|
|
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 { Options } from '@koa/cors';\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 rootQueryArgsByPath?: Map<string | number, 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 // Key args per root field (alias)\n if (!contextValue.rootQueryArgsByPath) {\n contextValue.rootQueryArgsByPath = new Map();\n }\n contextValue.rootQueryArgsByPath.set(info.path.key, {\n ...args,\n _originField: info.fieldName,\n });\n }\n },\n };\n },\n };\n },\n };\n\n type CustomOptions = {\n cors?: boolean | Options;\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: undefined,\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 (serverConfig.cors === false) {\n // Explicitly disabled - don't add middleware\n } else if (serverConfig.cors === undefined || serverConfig.cors === true) {\n // enable with defaults (backwards compatible)\n handler.push(cors());\n } else {\n // Custom options object\n handler.push(cors(serverConfig.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","rootQueryArgsByPath","Map","set","key","_originField","fieldName","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":";;;;;;;;;AAiBA,MAAMA,KAAAA,GAAQC,SAAAA,CAAU,CAACC,CAAAA,EAAGC,CAAAA,GAAAA;IAC1B,IAAIC,OAAAA,CAAQF,CAAAA,CAAAA,IAAME,OAAAA,CAAQD,CAAAA,CAAAA,EAAI;QAC5B,OAAOD,CAAAA,CAAEG,MAAM,CAACF,CAAAA,CAAAA;AA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JL,GAAAA,CAAIM,OAAO,CAACC,MAAM,KAAK,KAAA,IACvBP,GAAAA,CAAIM,OAAO,CAACE,GAAG,KAAK/C;QACpB7B,MAAAA,CAAOE,MAAM,CAAC,SAAA,CAAA,CAAWE,OAAO,CAAC,SAASS,UAAU,CAACgE,SAAS,EAAA;QAC9DT,GAAAA,CAAIM,OAAO,CAACI,MAAM,CAACC,MAAM,EAAEC,QAAAA,CAAS;;AAGtC,QAAA,IAAIP,mBAAAA,EAAqB;YACvB,OAAOJ,IAAAA,EAAAA;AACT,QAAA;AAEA,QAAA,OAAOrE,MAAAA,CAAOiF,IAAI,CAACC,YAAY,CAACd,GAAAA,EAAKC,IAAAA,CAAAA;AACvC,IAAA,CAAA,CAAA;;IAGAL,OAAAA,CAAQC,IAAI,CACVkB,aAAAA,CAA0DzB,MAAAA,EAAQ;;AAEhE0B,QAAAA,OAAAA,EAAS,OAAO,EAAEhB,GAAG,EAAE,IAAM;AAC3BE,gBAAAA,KAAAA,EAAOF,IAAIE,KAAK;gBAChBe,UAAAA,EAAYjB;aACd;AACF,KAAA,CAAA,CAAA;;IAIFpE,MAAAA,CAAO0D,MAAM,CAAC4B,MAAM,CAAC;AACnB,QAAA;YACEX,MAAAA,EAAQ,KAAA;AACR9C,YAAAA,IAAAA;AACAmC,YAAAA,OAAAA;YACA/D,MAAAA,EAAQ;gBACNgF,IAAAA,EAAM;AACR;AACF;AACD,KAAA,CAAA;;;;AAKDjF,IAAAA,MAAAA,CAAOE,MAAM,CAAC,SAAA,CAAA,CAAWqF,OAAO,GAAG,UAAA;AACjC,QAAA,MAAM7B,OAAO8B,IAAI,EAAA;AACnB,IAAA,CAAA;AACF;;;;"}
|
|
@@ -21,7 +21,7 @@ var associationResolvers = (({ strapi })=>{
|
|
|
21
21
|
const targetUID = isMediaAttribute ? 'plugin::upload.file' : attribute.target;
|
|
22
22
|
const isToMany = isMediaAttribute ? attribute.multiple : attribute.relation.endsWith('Many');
|
|
23
23
|
const targetContentType = strapi.getModel(targetUID);
|
|
24
|
-
return async (parent, args
|
|
24
|
+
return async (parent, args, context, info)=>{
|
|
25
25
|
const { auth } = context.state;
|
|
26
26
|
const transformedArgs = transformArgs(args, {
|
|
27
27
|
contentType: targetContentType,
|
|
@@ -41,8 +41,14 @@ var associationResolvers = (({ strapi })=>{
|
|
|
41
41
|
const graphqlService = strapi.plugin('graphql').service('content-api');
|
|
42
42
|
return graphqlService.isBuiltInQueryField(fieldName);
|
|
43
43
|
};
|
|
44
|
+
// Walk back to the root of info.path so we pick up the args of *our* query branch
|
|
45
|
+
let rootPath = info?.path;
|
|
46
|
+
while(rootPath?.prev){
|
|
47
|
+
rootPath = rootPath.prev;
|
|
48
|
+
}
|
|
49
|
+
const rootQueryArgs = rootPath ? context.rootQueryArgsByPath?.get(rootPath.key) : undefined;
|
|
44
50
|
// Only inherit status from built-in queries to avoid conflicts with custom resolvers
|
|
45
|
-
const inheritedStatus =
|
|
51
|
+
const inheritedStatus = rootQueryArgs?.status && rootQueryArgs?._originField && isBuiltInQueryField(rootQueryArgs._originField) ? rootQueryArgs.status : null;
|
|
46
52
|
const statusToApply = args.status || inheritedStatus;
|
|
47
53
|
const defaultFilters = isTargetDraftAndPublishContentType && statusToApply ? {
|
|
48
54
|
where: {
|
|
@@ -54,7 +60,7 @@ var associationResolvers = (({ strapi })=>{
|
|
|
54
60
|
}
|
|
55
61
|
} : {};
|
|
56
62
|
// Inherit hasPublishedVersion from root query (same pattern as status)
|
|
57
|
-
const inheritedHasPublishedVersion =
|
|
63
|
+
const inheritedHasPublishedVersion = rootQueryArgs?.hasPublishedVersion !== undefined && rootQueryArgs?._originField && isBuiltInQueryField(rootQueryArgs._originField) ? rootQueryArgs.hasPublishedVersion : undefined;
|
|
58
64
|
// Build hasPublishedVersion condition for this relation's model
|
|
59
65
|
let hasPublishedVersionFilters = {};
|
|
60
66
|
if (isTargetDraftAndPublishContentType && inheritedHasPublishedVersion !== undefined) {
|
|
@@ -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, 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\n // Helper to check if a field is from built-in queries (not custom resolvers)\n // Use the precomputed lookup populated by the content-api service at schema build time.\n const isBuiltInQueryField = (fieldName: string) => {\n const graphqlService = strapi.plugin('graphql').service('content-api');\n return graphqlService.isBuiltInQueryField(fieldName);\n };\n\n // Only inherit status from built-in queries to avoid conflicts with custom resolvers\n const inheritedStatus =\n context.rootQueryArgs?.status &&\n context.rootQueryArgs?._originField &&\n isBuiltInQueryField(context.rootQueryArgs._originField)\n ? context.rootQueryArgs.status\n : null;\n\n const statusToApply = args.status || inheritedStatus;\n\n const defaultFilters =\n isTargetDraftAndPublishContentType && statusToApply\n ? {\n where: {\n publishedAt: statusToApply === 'published' ? { $notNull: true } : { $null: true },\n },\n }\n : {};\n\n // Inherit hasPublishedVersion from root query (same pattern as status)\n const inheritedHasPublishedVersion =\n context.rootQueryArgs?.hasPublishedVersion !== undefined &&\n context.rootQueryArgs?._originField &&\n isBuiltInQueryField(context.rootQueryArgs._originField)\n ? context.rootQueryArgs.hasPublishedVersion\n : undefined;\n\n // Build hasPublishedVersion condition for this relation's model\n let hasPublishedVersionFilters: Record<string, any> = {};\n if (isTargetDraftAndPublishContentType && inheritedHasPublishedVersion !== undefined) {\n const meta = strapi.db.metadata.get(targetUID);\n const tableName = meta.tableName;\n const documentIdAttr = meta.attributes.documentId;\n const publishedAtAttr = meta.attributes.publishedAt;\n const documentIdColumn =\n ('columnName' in documentIdAttr && documentIdAttr.columnName) || 'document_id';\n const publishedAtColumn =\n ('columnName' in publishedAtAttr && publishedAtAttr.columnName) || 'published_at';\n\n const knex = strapi.db.connection;\n const subquery = knex(tableName)\n .distinct(documentIdColumn)\n .whereNotNull(publishedAtColumn);\n\n hasPublishedVersionFilters = {\n where: {\n documentId: inheritedHasPublishedVersion ? { $in: subquery } : { $notIn: subquery },\n },\n };\n }\n\n const dbQuery = merge(merge(defaultFilters, hasPublishedVersionFilters), transformedQuery);\n\n // Sign media URLs if upload plugin is available and using private provider\n const data = await (async () => {\n const rawData = await strapi.db\n .query(contentTypeUID)\n .load(parent, attributeName, dbQuery);\n if (isMediaAttribute && strapi.plugin('upload')) {\n const { signFileUrls } = strapi.plugin('upload').service('file');\n\n if (Array.isArray(rawData)) {\n return async.map(rawData, (item: any) => signFileUrls(item));\n }\n\n if (rawData) {\n return signFileUrls(rawData);\n }\n }\n\n return rawData;\n })();\n\n const sanitizeInfo = {\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, sanitizeInfo);\n }\n\n // Else, it returns an object that matches\n // what the entity-response's resolvers expect\n return toEntityResponse(data, sanitizeInfo);\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","isBuiltInQueryField","fieldName","graphqlService","inheritedStatus","rootQueryArgs","status","_originField","statusToApply","defaultFilters","where","publishedAt","$notNull","$null","inheritedHasPublishedVersion","hasPublishedVersion","undefined","hasPublishedVersionFilters","meta","db","metadata","tableName","documentIdAttr","documentId","publishedAtAttr","documentIdColumn","columnName","publishedAtColumn","knex","connection","subquery","distinct","whereNotNull","$in","$notIn","dbQuery","merge","data","rawData","load","signFileUrls","Array","isArray","async","map","item","sanitizeInfo","resourceUID","wrapData","dataToWrap","sanitizeData","dataToSanitize","output","unwrapData","sanitizeMorphAttribute","pipe"],"mappings":";;;;;AAMA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;AAE7B,2BAAe,CAAA,CAAC,EAAEC,MAAM,EAAW,GAAA;AACjC,IAAA,MAAM,EAAEC,OAAAA,EAASC,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,MAAAA,CAAOgB,QAAQ,CAACH,cAAAA,CAAAA;AACpC,YAAA,MAAMI,SAAAA,GAAiBF,WAAAA,CAAYT,UAAU,CAACQ,aAAAA,CAAc;AAE5D,YAAA,IAAI,CAACG,SAAAA,EAAW;gBACd,MAAM,IAAInB,iBACR,CAAC,4CAA4C,EAAEe,cAAAA,CAAe,EAAE,EAAEC,aAAAA,CAAAA,CAAe,CAAA;AAErF,YAAA;AAEA,YAAA,MAAMI,mBAAmBb,OAAAA,CAAQY,SAAAA,CAAAA;AACjC,YAAA,MAAME,mBAAmBf,eAAAA,CAAgBa,SAAAA,CAAAA;AAEzC,YAAA,MAAMG,SAAAA,GAAYF,gBAAAA,GAAmB,qBAAA,GAAwBD,SAAAA,CAAUI,MAAM;YAC7E,MAAMC,QAAAA,GAAWJ,mBAAmBD,SAAAA,CAAUM,QAAQ,GAAGN,SAAAA,CAAUO,QAAQ,CAACC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AAA;;;;AAKA,gBAAA,IAAID,gBAAAA,EAAkB;;oBAEpB,MAAMyE,QAAAA,GAAW,CAACC,UAAAA,IAAqB;AAAE,4BAAA,CAAC/E,gBAAgB+E;yBAAW,CAAA;AACrE,oBAAA,MAAMC,eAAe,CAACC,cAAAA,GAAAA;wBACpB,OAAO/F,MAAAA,CAAOkC,UAAU,CAACI,QAAQ,CAAC0D,MAAM,CAACD,gBAAgBhF,WAAAA,EAAa;AAAEe,4BAAAA;AAAK,yBAAA,CAAA;AAC/E,oBAAA,CAAA;AACA,oBAAA,MAAMmE,aAAazD,MAAAA,CAAI1B,aAAAA,CAAAA;;AAGvB,oBAAA,MAAMoF,sBAAAA,GAAyBX,WAAAA,CAAMY,IAAI,CAACP,UAAUE,YAAAA,EAAcG,UAAAA,CAAAA;AAElE,oBAAA,OAAOC,sBAAAA,CAAuBjB,IAAAA,CAAAA;AAChC,gBAAA;;;AAIA,gBAAA,IAAI3D,QAAAA,EAAU;AACZ,oBAAA,OAAOZ,2BAA2BuE,IAAAA,EAAMS,YAAAA,CAAAA;AAC1C,gBAAA;;;AAIA,gBAAA,OAAOjF,iBAAiBwE,IAAAA,EAAMS,YAAAA,CAAAA;AAChC,YAAA,CAAA;AACF,QAAA;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, info: 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\n // Helper to check if a field is from built-in queries (not custom resolvers)\n // Use the precomputed lookup populated by the content-api service at schema build time.\n const isBuiltInQueryField = (fieldName: string) => {\n const graphqlService = strapi.plugin('graphql').service('content-api');\n return graphqlService.isBuiltInQueryField(fieldName);\n };\n\n // Walk back to the root of info.path so we pick up the args of *our* query branch\n let rootPath = info?.path;\n while (rootPath?.prev) {\n rootPath = rootPath.prev;\n }\n const rootQueryArgs = rootPath ? context.rootQueryArgsByPath?.get(rootPath.key) : undefined;\n\n // Only inherit status from built-in queries to avoid conflicts with custom resolvers\n const inheritedStatus =\n rootQueryArgs?.status &&\n rootQueryArgs?._originField &&\n isBuiltInQueryField(rootQueryArgs._originField)\n ? rootQueryArgs.status\n : null;\n\n const statusToApply = args.status || inheritedStatus;\n\n const defaultFilters =\n isTargetDraftAndPublishContentType && statusToApply\n ? {\n where: {\n publishedAt: statusToApply === 'published' ? { $notNull: true } : { $null: true },\n },\n }\n : {};\n\n // Inherit hasPublishedVersion from root query (same pattern as status)\n const inheritedHasPublishedVersion =\n rootQueryArgs?.hasPublishedVersion !== undefined &&\n rootQueryArgs?._originField &&\n isBuiltInQueryField(rootQueryArgs._originField)\n ? rootQueryArgs.hasPublishedVersion\n : undefined;\n\n // Build hasPublishedVersion condition for this relation's model\n let hasPublishedVersionFilters: Record<string, any> = {};\n if (isTargetDraftAndPublishContentType && inheritedHasPublishedVersion !== undefined) {\n const meta = strapi.db.metadata.get(targetUID);\n const tableName = meta.tableName;\n const documentIdAttr = meta.attributes.documentId;\n const publishedAtAttr = meta.attributes.publishedAt;\n const documentIdColumn =\n ('columnName' in documentIdAttr && documentIdAttr.columnName) || 'document_id';\n const publishedAtColumn =\n ('columnName' in publishedAtAttr && publishedAtAttr.columnName) || 'published_at';\n\n const knex = strapi.db.connection;\n const subquery = knex(tableName)\n .distinct(documentIdColumn)\n .whereNotNull(publishedAtColumn);\n\n hasPublishedVersionFilters = {\n where: {\n documentId: inheritedHasPublishedVersion ? { $in: subquery } : { $notIn: subquery },\n },\n };\n }\n\n const dbQuery = merge(merge(defaultFilters, hasPublishedVersionFilters), transformedQuery);\n\n // Sign media URLs if upload plugin is available and using private provider\n const data = await (async () => {\n const rawData = await strapi.db\n .query(contentTypeUID)\n .load(parent, attributeName, dbQuery);\n if (isMediaAttribute && strapi.plugin('upload')) {\n const { signFileUrls } = strapi.plugin('upload').service('file');\n\n if (Array.isArray(rawData)) {\n return async.map(rawData, (item: any) => signFileUrls(item));\n }\n\n if (rawData) {\n return signFileUrls(rawData);\n }\n }\n\n return rawData;\n })();\n\n const sanitizeInfo = {\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, sanitizeInfo);\n }\n\n // Else, it returns an object that matches\n // what the entity-response's resolvers expect\n return toEntityResponse(data, sanitizeInfo);\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","info","auth","state","transformedArgs","usePagination","contentAPI","validate","query","sanitizedQuery","sanitize","transformedQuery","get","transform","isTargetDraftAndPublishContentType","contentTypes","hasDraftAndPublish","isBuiltInQueryField","fieldName","graphqlService","rootPath","path","prev","rootQueryArgs","rootQueryArgsByPath","key","undefined","inheritedStatus","status","_originField","statusToApply","defaultFilters","where","publishedAt","$notNull","$null","inheritedHasPublishedVersion","hasPublishedVersion","hasPublishedVersionFilters","meta","db","metadata","tableName","documentIdAttr","documentId","publishedAtAttr","documentIdColumn","columnName","publishedAtColumn","knex","connection","subquery","distinct","whereNotNull","$in","$notIn","dbQuery","merge","data","rawData","load","signFileUrls","Array","isArray","async","map","item","sanitizeInfo","resourceUID","wrapData","dataToWrap","sanitizeData","dataToSanitize","output","unwrapData","sanitizeMorphAttribute","pipe"],"mappings":";;;;;AAMA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;AAE7B,2BAAe,CAAA,CAAC,EAAEC,MAAM,EAAW,GAAA;AACjC,IAAA,MAAM,EAAEC,OAAAA,EAASC,iBAAiB,EAAE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E,QAAAA,GAAW,CAACC,UAAAA,IAAqB;AAAE,4BAAA,CAACrF,gBAAgBqF;yBAAW,CAAA;AACrE,oBAAA,MAAMC,eAAe,CAACC,cAAAA,GAAAA;wBACpB,OAAOrG,MAAAA,CAAOmC,UAAU,CAACI,QAAQ,CAAC+D,MAAM,CAACD,gBAAgBtF,WAAAA,EAAa;AAAEgB,4BAAAA;AAAK,yBAAA,CAAA;AAC/E,oBAAA,CAAA;AACA,oBAAA,MAAMwE,aAAa9D,MAAAA,CAAI3B,aAAAA,CAAAA;;AAGvB,oBAAA,MAAM0F,sBAAAA,GAAyBX,WAAAA,CAAMY,IAAI,CAACP,UAAUE,YAAAA,EAAcG,UAAAA,CAAAA;AAElE,oBAAA,OAAOC,sBAAAA,CAAuBjB,IAAAA,CAAAA;AAChC,gBAAA;;;AAIA,gBAAA,IAAIjE,QAAAA,EAAU;AACZ,oBAAA,OAAOZ,2BAA2B6E,IAAAA,EAAMS,YAAAA,CAAAA;AAC1C,gBAAA;;;AAIA,gBAAA,OAAOvF,iBAAiB8E,IAAAA,EAAMS,YAAAA,CAAAA;AAChC,YAAA,CAAA;AACF,QAAA;AACF,KAAA;AACF,CAAA;;;;"}
|
|
@@ -19,7 +19,7 @@ var associationResolvers = (({ strapi })=>{
|
|
|
19
19
|
const targetUID = isMediaAttribute ? 'plugin::upload.file' : attribute.target;
|
|
20
20
|
const isToMany = isMediaAttribute ? attribute.multiple : attribute.relation.endsWith('Many');
|
|
21
21
|
const targetContentType = strapi.getModel(targetUID);
|
|
22
|
-
return async (parent, args
|
|
22
|
+
return async (parent, args, context, info)=>{
|
|
23
23
|
const { auth } = context.state;
|
|
24
24
|
const transformedArgs = transformArgs(args, {
|
|
25
25
|
contentType: targetContentType,
|
|
@@ -39,8 +39,14 @@ var associationResolvers = (({ strapi })=>{
|
|
|
39
39
|
const graphqlService = strapi.plugin('graphql').service('content-api');
|
|
40
40
|
return graphqlService.isBuiltInQueryField(fieldName);
|
|
41
41
|
};
|
|
42
|
+
// Walk back to the root of info.path so we pick up the args of *our* query branch
|
|
43
|
+
let rootPath = info?.path;
|
|
44
|
+
while(rootPath?.prev){
|
|
45
|
+
rootPath = rootPath.prev;
|
|
46
|
+
}
|
|
47
|
+
const rootQueryArgs = rootPath ? context.rootQueryArgsByPath?.get(rootPath.key) : undefined;
|
|
42
48
|
// Only inherit status from built-in queries to avoid conflicts with custom resolvers
|
|
43
|
-
const inheritedStatus =
|
|
49
|
+
const inheritedStatus = rootQueryArgs?.status && rootQueryArgs?._originField && isBuiltInQueryField(rootQueryArgs._originField) ? rootQueryArgs.status : null;
|
|
44
50
|
const statusToApply = args.status || inheritedStatus;
|
|
45
51
|
const defaultFilters = isTargetDraftAndPublishContentType && statusToApply ? {
|
|
46
52
|
where: {
|
|
@@ -52,7 +58,7 @@ var associationResolvers = (({ strapi })=>{
|
|
|
52
58
|
}
|
|
53
59
|
} : {};
|
|
54
60
|
// Inherit hasPublishedVersion from root query (same pattern as status)
|
|
55
|
-
const inheritedHasPublishedVersion =
|
|
61
|
+
const inheritedHasPublishedVersion = rootQueryArgs?.hasPublishedVersion !== undefined && rootQueryArgs?._originField && isBuiltInQueryField(rootQueryArgs._originField) ? rootQueryArgs.hasPublishedVersion : undefined;
|
|
56
62
|
// Build hasPublishedVersion condition for this relation's model
|
|
57
63
|
let hasPublishedVersionFilters = {};
|
|
58
64
|
if (isTargetDraftAndPublishContentType && inheritedHasPublishedVersion !== undefined) {
|
|
@@ -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, 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\n // Helper to check if a field is from built-in queries (not custom resolvers)\n // Use the precomputed lookup populated by the content-api service at schema build time.\n const isBuiltInQueryField = (fieldName: string) => {\n const graphqlService = strapi.plugin('graphql').service('content-api');\n return graphqlService.isBuiltInQueryField(fieldName);\n };\n\n // Only inherit status from built-in queries to avoid conflicts with custom resolvers\n const inheritedStatus =\n context.rootQueryArgs?.status &&\n context.rootQueryArgs?._originField &&\n isBuiltInQueryField(context.rootQueryArgs._originField)\n ? context.rootQueryArgs.status\n : null;\n\n const statusToApply = args.status || inheritedStatus;\n\n const defaultFilters =\n isTargetDraftAndPublishContentType && statusToApply\n ? {\n where: {\n publishedAt: statusToApply === 'published' ? { $notNull: true } : { $null: true },\n },\n }\n : {};\n\n // Inherit hasPublishedVersion from root query (same pattern as status)\n const inheritedHasPublishedVersion =\n context.rootQueryArgs?.hasPublishedVersion !== undefined &&\n context.rootQueryArgs?._originField &&\n isBuiltInQueryField(context.rootQueryArgs._originField)\n ? context.rootQueryArgs.hasPublishedVersion\n : undefined;\n\n // Build hasPublishedVersion condition for this relation's model\n let hasPublishedVersionFilters: Record<string, any> = {};\n if (isTargetDraftAndPublishContentType && inheritedHasPublishedVersion !== undefined) {\n const meta = strapi.db.metadata.get(targetUID);\n const tableName = meta.tableName;\n const documentIdAttr = meta.attributes.documentId;\n const publishedAtAttr = meta.attributes.publishedAt;\n const documentIdColumn =\n ('columnName' in documentIdAttr && documentIdAttr.columnName) || 'document_id';\n const publishedAtColumn =\n ('columnName' in publishedAtAttr && publishedAtAttr.columnName) || 'published_at';\n\n const knex = strapi.db.connection;\n const subquery = knex(tableName)\n .distinct(documentIdColumn)\n .whereNotNull(publishedAtColumn);\n\n hasPublishedVersionFilters = {\n where: {\n documentId: inheritedHasPublishedVersion ? { $in: subquery } : { $notIn: subquery },\n },\n };\n }\n\n const dbQuery = merge(merge(defaultFilters, hasPublishedVersionFilters), transformedQuery);\n\n // Sign media URLs if upload plugin is available and using private provider\n const data = await (async () => {\n const rawData = await strapi.db\n .query(contentTypeUID)\n .load(parent, attributeName, dbQuery);\n if (isMediaAttribute && strapi.plugin('upload')) {\n const { signFileUrls } = strapi.plugin('upload').service('file');\n\n if (Array.isArray(rawData)) {\n return async.map(rawData, (item: any) => signFileUrls(item));\n }\n\n if (rawData) {\n return signFileUrls(rawData);\n }\n }\n\n return rawData;\n })();\n\n const sanitizeInfo = {\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, sanitizeInfo);\n }\n\n // Else, it returns an object that matches\n // what the entity-response's resolvers expect\n return toEntityResponse(data, sanitizeInfo);\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","isBuiltInQueryField","fieldName","graphqlService","inheritedStatus","rootQueryArgs","status","_originField","statusToApply","defaultFilters","where","publishedAt","$notNull","$null","inheritedHasPublishedVersion","hasPublishedVersion","undefined","hasPublishedVersionFilters","meta","db","metadata","tableName","documentIdAttr","documentId","publishedAtAttr","documentIdColumn","columnName","publishedAtColumn","knex","connection","subquery","distinct","whereNotNull","$in","$notIn","dbQuery","merge","data","rawData","load","signFileUrls","Array","isArray","async","map","item","sanitizeInfo","resourceUID","wrapData","dataToWrap","sanitizeData","dataToSanitize","output","unwrapData","sanitizeMorphAttribute","pipe"],"mappings":";;;AAMA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,MAAAA;AAE7B,2BAAe,CAAA,CAAC,EAAEC,MAAM,EAAW,GAAA;AACjC,IAAA,MAAM,EAAEC,OAAAA,EAASC,iBAAiB,EAAE,GAAGF,MAAAA,CAAOG,MAAM,CAAC,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K,yBAAA,CAAA;AAC/E,oBAAA,CAAA;AACA,oBAAA,MAAMmE,aAAazD,GAAAA,CAAI1B,aAAAA,CAAAA;;AAGvB,oBAAA,MAAMoF,sBAAAA,GAAyBX,KAAAA,CAAMY,IAAI,CAACP,UAAUE,YAAAA,EAAcG,UAAAA,CAAAA;AAElE,oBAAA,OAAOC,sBAAAA,CAAuBjB,IAAAA,CAAAA;AAChC,gBAAA;;;AAIA,gBAAA,IAAI3D,QAAAA,EAAU;AACZ,oBAAA,OAAOZ,2BAA2BuE,IAAAA,EAAMS,YAAAA,CAAAA;AAC1C,gBAAA;;;AAIA,gBAAA,OAAOjF,iBAAiBwE,IAAAA,EAAMS,YAAAA,CAAAA;AAChC,YAAA,CAAA;AACF,QAAA;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, info: 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\n // Helper to check if a field is from built-in queries (not custom resolvers)\n // Use the precomputed lookup populated by the content-api service at schema build time.\n const isBuiltInQueryField = (fieldName: string) => {\n const graphqlService = strapi.plugin('graphql').service('content-api');\n return graphqlService.isBuiltInQueryField(fieldName);\n };\n\n // Walk back to the root of info.path so we pick up the args of *our* query branch\n let rootPath = info?.path;\n while (rootPath?.prev) {\n rootPath = rootPath.prev;\n }\n const rootQueryArgs = rootPath ? context.rootQueryArgsByPath?.get(rootPath.key) : undefined;\n\n // Only inherit status from built-in queries to avoid conflicts with custom resolvers\n const inheritedStatus =\n rootQueryArgs?.status &&\n rootQueryArgs?._originField &&\n isBuiltInQueryField(rootQueryArgs._originField)\n ? rootQueryArgs.status\n : null;\n\n const statusToApply = args.status || inheritedStatus;\n\n const defaultFilters =\n isTargetDraftAndPublishContentType && statusToApply\n ? {\n where: {\n publishedAt: statusToApply === 'published' ? { $notNull: true } : { $null: true },\n },\n }\n : {};\n\n // Inherit hasPublishedVersion from root query (same pattern as status)\n const inheritedHasPublishedVersion =\n rootQueryArgs?.hasPublishedVersion !== undefined &&\n rootQueryArgs?._originField &&\n isBuiltInQueryField(rootQueryArgs._originField)\n ? rootQueryArgs.hasPublishedVersion\n : undefined;\n\n // Build hasPublishedVersion condition for this relation's model\n let hasPublishedVersionFilters: Record<string, any> = {};\n if (isTargetDraftAndPublishContentType && inheritedHasPublishedVersion !== undefined) {\n const meta = strapi.db.metadata.get(targetUID);\n const tableName = meta.tableName;\n const documentIdAttr = meta.attributes.documentId;\n const publishedAtAttr = meta.attributes.publishedAt;\n const documentIdColumn =\n ('columnName' in documentIdAttr && documentIdAttr.columnName) || 'document_id';\n const publishedAtColumn =\n ('columnName' in publishedAtAttr && publishedAtAttr.columnName) || 'published_at';\n\n const knex = strapi.db.connection;\n const subquery = knex(tableName)\n .distinct(documentIdColumn)\n .whereNotNull(publishedAtColumn);\n\n hasPublishedVersionFilters = {\n where: {\n documentId: inheritedHasPublishedVersion ? { $in: subquery } : { $notIn: subquery },\n },\n };\n }\n\n const dbQuery = merge(merge(defaultFilters, hasPublishedVersionFilters), transformedQuery);\n\n // Sign media URLs if upload plugin is available and using private provider\n const data = await (async () => {\n const rawData = await strapi.db\n .query(contentTypeUID)\n .load(parent, attributeName, dbQuery);\n if (isMediaAttribute && strapi.plugin('upload')) {\n const { signFileUrls } = strapi.plugin('upload').service('file');\n\n if (Array.isArray(rawData)) {\n return async.map(rawData, (item: any) => signFileUrls(item));\n }\n\n if (rawData) {\n return signFileUrls(rawData);\n }\n }\n\n return rawData;\n })();\n\n const sanitizeInfo = {\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, sanitizeInfo);\n }\n\n // Else, it returns an object that matches\n // what the entity-response's resolvers expect\n return toEntityResponse(data, sanitizeInfo);\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","info","auth","state","transformedArgs","usePagination","contentAPI","validate","query","sanitizedQuery","sanitize","transformedQuery","get","transform","isTargetDraftAndPublishContentType","contentTypes","hasDraftAndPublish","isBuiltInQueryField","fieldName","graphqlService","rootPath","path","prev","rootQueryArgs","rootQueryArgsByPath","key","undefined","inheritedStatus","status","_originField","statusToApply","defaultFilters","where","publishedAt","$notNull","$null","inheritedHasPublishedVersion","hasPublishedVersion","hasPublishedVersionFilters","meta","db","metadata","tableName","documentIdAttr","documentId","publishedAtAttr","documentIdColumn","columnName","publishedAtColumn","knex","connection","subquery","distinct","whereNotNull","$in","$notIn","dbQuery","merge","data","rawData","load","signFileUrls","Array","isArray","async","map","item","sanitizeInfo","resourceUID","wrapData","dataToWrap","sanitizeData","dataToSanitize","output","unwrapData","sanitizeMorphAttribute","pipe"],"mappings":";;;AAMA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,MAAAA;AAE7B,2BAAe,CAAA,CAAC,EAAEC,MAAM,EAAW,GAAA;AACjC,IAAA,MAAM,EAAEC,OAAAA,EAASC,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;A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a9D,GAAAA,CAAI3B,aAAAA,CAAAA;;AAGvB,oBAAA,MAAM0F,sBAAAA,GAAyBX,KAAAA,CAAMY,IAAI,CAACP,UAAUE,YAAAA,EAAcG,UAAAA,CAAAA;AAElE,oBAAA,OAAOC,sBAAAA,CAAuBjB,IAAAA,CAAAA;AAChC,gBAAA;;;AAIA,gBAAA,IAAIjE,QAAAA,EAAU;AACZ,oBAAA,OAAOZ,2BAA2B6E,IAAAA,EAAMS,YAAAA,CAAAA;AAC1C,gBAAA;;;AAIA,gBAAA,OAAOvF,iBAAiB8E,IAAAA,EAAMS,YAAAA,CAAAA;AAChC,YAAA,CAAA;AACF,QAAA;AACF,KAAA;AACF,CAAA;;;;"}
|
|
@@ -24,8 +24,8 @@ var utils = (({ strapi })=>{
|
|
|
24
24
|
const { kind } = contentType;
|
|
25
25
|
// On non–D&P roots (e.g. User) these args do not version the parent document, but they
|
|
26
26
|
// are required: association resolvers inherit them into nested D&P relations (see
|
|
27
|
-
// builders/resolvers/association.ts +
|
|
28
|
-
// control for populated relations (e.g. github.com/strapi/strapi/issues/25746).
|
|
27
|
+
// builders/resolvers/association.ts + rootQueryArgsByPath). Omitting them broke
|
|
28
|
+
// draft/published control for populated relations (e.g. github.com/strapi/strapi/issues/25746).
|
|
29
29
|
//
|
|
30
30
|
// Future direction: add `status` / `hasPublishedVersion` to GraphQL args on nested
|
|
31
31
|
// to-many (and to-one) relation fields when the *target* content type has D&P, instead
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../server/src/services/builders/utils.ts"],"sourcesContent":["import { entries, mapValues, omit } from 'lodash/fp';\nimport { idArg, nonNull } from 'nexus';\nimport { pagination } from '@strapi/utils';\nimport type { Core, Struct } from '@strapi/types';\n\nconst { withDefaultPagination } = pagination;\n\ntype ContentTypeArgsOptions = {\n multiple?: boolean;\n isNested?: boolean;\n};\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => {\n const { service: getService } = strapi.plugin('graphql');\n\n return {\n getContentTypeArgs(\n contentType: Struct.Schema,\n { multiple = true, isNested = false }: ContentTypeArgsOptions = {}\n ) {\n const { naming } = getService('utils');\n const { args } = getService('internals');\n\n const { modelType } = contentType;\n\n // Components\n if (modelType === 'component') {\n if (!multiple) return {};\n\n return {\n filters: naming.getFiltersInputTypeName(contentType),\n pagination: args.PaginationArg,\n sort: args.SortArg,\n };\n }\n\n const { kind } = contentType;\n\n // On non–D&P roots (e.g. User) these args do not version the parent document, but they\n // are required: association resolvers inherit them into nested D&P relations (see\n // builders/resolvers/association.ts +
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../server/src/services/builders/utils.ts"],"sourcesContent":["import { entries, mapValues, omit } from 'lodash/fp';\nimport { idArg, nonNull } from 'nexus';\nimport { pagination } from '@strapi/utils';\nimport type { Core, Struct } from '@strapi/types';\n\nconst { withDefaultPagination } = pagination;\n\ntype ContentTypeArgsOptions = {\n multiple?: boolean;\n isNested?: boolean;\n};\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => {\n const { service: getService } = strapi.plugin('graphql');\n\n return {\n getContentTypeArgs(\n contentType: Struct.Schema,\n { multiple = true, isNested = false }: ContentTypeArgsOptions = {}\n ) {\n const { naming } = getService('utils');\n const { args } = getService('internals');\n\n const { modelType } = contentType;\n\n // Components\n if (modelType === 'component') {\n if (!multiple) return {};\n\n return {\n filters: naming.getFiltersInputTypeName(contentType),\n pagination: args.PaginationArg,\n sort: args.SortArg,\n };\n }\n\n const { kind } = contentType;\n\n // On non–D&P roots (e.g. User) these args do not version the parent document, but they\n // are required: association resolvers inherit them into nested D&P relations (see\n // builders/resolvers/association.ts + rootQueryArgsByPath). Omitting them broke\n // draft/published control for populated relations (e.g. github.com/strapi/strapi/issues/25746).\n //\n // Future direction: add `status` / `hasPublishedVersion` to GraphQL args on nested\n // to-many (and to-one) relation fields when the *target* content type has D&P, instead\n // of relying on root-level “context” that is easy to misread (args on User affecting\n // Articles). That would allow different publication settings per relation branch, match\n // how developers think about the graph, and let non-DP roots drop these args if desired.\n // Would require extending getContentTypeArgs(..., { isNested: true }) for D&P targets\n // and teaching association.ts to honor args.hasPublishedVersion on nested fields, not\n // only root inheritance.\n const publicationArgs = {\n status: args.PublicationStatusArg,\n hasPublishedVersion: args.HasPublishedVersionArg,\n };\n\n // Collection Types\n if (kind === 'collectionType') {\n if (!multiple) {\n return {\n documentId: nonNull(idArg()),\n ...publicationArgs,\n };\n }\n\n const params: Record<string, unknown> = {\n filters: naming.getFiltersInputTypeName(contentType),\n pagination: args.PaginationArg,\n sort: args.SortArg,\n };\n\n if (!isNested) {\n Object.assign(params, publicationArgs);\n }\n\n return params;\n }\n\n // Single Types\n if (kind === 'singleType') {\n const params: Record<string, unknown> = {};\n\n if (!isNested) {\n Object.assign(params, publicationArgs);\n }\n\n return params;\n }\n },\n\n /**\n * Filter an object entries and keep only those whose value is a unique scalar attribute\n */\n getUniqueScalarAttributes(attributes: Struct.SchemaAttributes) {\n const { isStrapiScalar } = getService('utils').attributes;\n\n const uniqueAttributes = entries(attributes).filter(\n ([, attribute]) => isStrapiScalar(attribute) && 'unique' in attribute && attribute.unique\n );\n\n return Object.fromEntries(uniqueAttributes);\n },\n\n /**\n * Map each value from an attribute to a FiltersInput type name\n * @param {object} attributes - The attributes object to transform\n * @return {Object<string, string>}\n */\n scalarAttributesToFiltersMap(attributes: Struct.SchemaAttributes) {\n return mapValues((attribute) => {\n const { mappers, naming } = getService('utils');\n\n const gqlScalar = mappers.strapiScalarToGraphQLScalar(attribute.type);\n\n return naming.getScalarFilterInputTypeName(gqlScalar);\n }, attributes);\n },\n\n /**\n * Apply basic transform to GQL args\n */\n transformArgs(\n args: any,\n {\n contentType,\n usePagination = false,\n }: { contentType: Struct.ContentTypeSchema; usePagination?: boolean }\n ) {\n const { mappers } = getService('utils');\n const { config } = strapi.plugin('graphql');\n const { pagination = {}, filters = {} } = args;\n\n // Init\n const newArgs = omit(['pagination', 'filters'], args);\n\n // Pagination\n if (usePagination) {\n const defaultLimit: number = config('defaultLimit');\n const maxLimit: number = config('maxLimit');\n\n Object.assign(\n newArgs,\n withDefaultPagination(pagination, {\n maxLimit,\n defaults: {\n offset: { limit: defaultLimit },\n page: { pageSize: defaultLimit },\n },\n })\n );\n }\n\n // Filters\n if (args.filters) {\n Object.assign(newArgs, {\n filters: mappers.graphQLFiltersToStrapiQuery(filters, contentType),\n });\n }\n\n return newArgs;\n },\n };\n};\n"],"names":["withDefaultPagination","pagination","strapi","service","getService","plugin","getContentTypeArgs","contentType","multiple","isNested","naming","args","modelType","filters","getFiltersInputTypeName","PaginationArg","sort","SortArg","kind","publicationArgs","status","PublicationStatusArg","hasPublishedVersion","HasPublishedVersionArg","documentId","nonNull","idArg","params","Object","assign","getUniqueScalarAttributes","attributes","isStrapiScalar","uniqueAttributes","entries","filter","attribute","unique","fromEntries","scalarAttributesToFiltersMap","mapValues","mappers","gqlScalar","strapiScalarToGraphQLScalar","type","getScalarFilterInputTypeName","transformArgs","usePagination","config","newArgs","omit","defaultLimit","maxLimit","defaults","offset","limit","page","pageSize","graphQLFiltersToStrapiQuery"],"mappings":";;;;;;AAKA,MAAM,EAAEA,qBAAqB,EAAE,GAAGC,kBAAAA;AAOlC,YAAe,CAAA,CAAC,EAAEC,MAAM,EAA2B,GAAA;AACjD,IAAA,MAAM,EAAEC,OAAAA,EAASC,UAAU,EAAE,GAAGF,MAAAA,CAAOG,MAAM,CAAC,SAAA,CAAA;IAE9C,OAAO;QACLC,kBAAAA,CAAAA,CACEC,WAA0B,EAC1B,EAAEC,QAAAA,GAAW,IAAI,EAAEC,QAAAA,GAAW,KAAK,EAA0B,GAAG,EAAE,EAAA;AAElE,YAAA,MAAM,EAAEC,MAAM,EAAE,GAAGN,UAAAA,CAAW,OAAA,CAAA;AAC9B,YAAA,MAAM,EAAEO,IAAI,EAAE,GAAGP,UAAAA,CAAW,WAAA,CAAA;YAE5B,MAAM,EAAEQ,SAAS,EAAE,GAAGL,WAAAA;;AAGtB,YAAA,I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AIoC,aAAAA,EAAe;AACjB,gBAAA,MAAMI,eAAuBH,MAAAA,CAAO,cAAA,CAAA;AACpC,gBAAA,MAAMI,WAAmBJ,MAAAA,CAAO,UAAA,CAAA;AAEhCpB,gBAAAA,MAAAA,CAAOC,MAAM,CACXoB,OAAAA,EACAjD,qBAAAA,CAAsBC,UAAAA,EAAY;AAChCmD,oBAAAA,QAAAA;oBACAC,QAAAA,EAAU;wBACRC,MAAAA,EAAQ;4BAAEC,KAAAA,EAAOJ;AAAa,yBAAA;wBAC9BK,IAAAA,EAAM;4BAAEC,QAAAA,EAAUN;AAAa;AACjC;AACF,iBAAA,CAAA,CAAA;AAEJ,YAAA;;YAGA,IAAIxC,IAAAA,CAAKE,OAAO,EAAE;gBAChBe,MAAAA,CAAOC,MAAM,CAACoB,OAAAA,EAAS;oBACrBpC,OAAAA,EAAS4B,OAAAA,CAAQiB,2BAA2B,CAAC7C,OAAAA,EAASN,WAAAA;AACxD,iBAAA,CAAA;AACF,YAAA;YAEA,OAAO0C,OAAAA;AACT,QAAA;AACF,KAAA;AACF,CAAA;;;;"}
|
|
@@ -22,8 +22,8 @@ var utils = (({ strapi })=>{
|
|
|
22
22
|
const { kind } = contentType;
|
|
23
23
|
// On non–D&P roots (e.g. User) these args do not version the parent document, but they
|
|
24
24
|
// are required: association resolvers inherit them into nested D&P relations (see
|
|
25
|
-
// builders/resolvers/association.ts +
|
|
26
|
-
// control for populated relations (e.g. github.com/strapi/strapi/issues/25746).
|
|
25
|
+
// builders/resolvers/association.ts + rootQueryArgsByPath). Omitting them broke
|
|
26
|
+
// draft/published control for populated relations (e.g. github.com/strapi/strapi/issues/25746).
|
|
27
27
|
//
|
|
28
28
|
// Future direction: add `status` / `hasPublishedVersion` to GraphQL args on nested
|
|
29
29
|
// to-many (and to-one) relation fields when the *target* content type has D&P, instead
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../../server/src/services/builders/utils.ts"],"sourcesContent":["import { entries, mapValues, omit } from 'lodash/fp';\nimport { idArg, nonNull } from 'nexus';\nimport { pagination } from '@strapi/utils';\nimport type { Core, Struct } from '@strapi/types';\n\nconst { withDefaultPagination } = pagination;\n\ntype ContentTypeArgsOptions = {\n multiple?: boolean;\n isNested?: boolean;\n};\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => {\n const { service: getService } = strapi.plugin('graphql');\n\n return {\n getContentTypeArgs(\n contentType: Struct.Schema,\n { multiple = true, isNested = false }: ContentTypeArgsOptions = {}\n ) {\n const { naming } = getService('utils');\n const { args } = getService('internals');\n\n const { modelType } = contentType;\n\n // Components\n if (modelType === 'component') {\n if (!multiple) return {};\n\n return {\n filters: naming.getFiltersInputTypeName(contentType),\n pagination: args.PaginationArg,\n sort: args.SortArg,\n };\n }\n\n const { kind } = contentType;\n\n // On non–D&P roots (e.g. User) these args do not version the parent document, but they\n // are required: association resolvers inherit them into nested D&P relations (see\n // builders/resolvers/association.ts +
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../../server/src/services/builders/utils.ts"],"sourcesContent":["import { entries, mapValues, omit } from 'lodash/fp';\nimport { idArg, nonNull } from 'nexus';\nimport { pagination } from '@strapi/utils';\nimport type { Core, Struct } from '@strapi/types';\n\nconst { withDefaultPagination } = pagination;\n\ntype ContentTypeArgsOptions = {\n multiple?: boolean;\n isNested?: boolean;\n};\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => {\n const { service: getService } = strapi.plugin('graphql');\n\n return {\n getContentTypeArgs(\n contentType: Struct.Schema,\n { multiple = true, isNested = false }: ContentTypeArgsOptions = {}\n ) {\n const { naming } = getService('utils');\n const { args } = getService('internals');\n\n const { modelType } = contentType;\n\n // Components\n if (modelType === 'component') {\n if (!multiple) return {};\n\n return {\n filters: naming.getFiltersInputTypeName(contentType),\n pagination: args.PaginationArg,\n sort: args.SortArg,\n };\n }\n\n const { kind } = contentType;\n\n // On non–D&P roots (e.g. User) these args do not version the parent document, but they\n // are required: association resolvers inherit them into nested D&P relations (see\n // builders/resolvers/association.ts + rootQueryArgsByPath). Omitting them broke\n // draft/published control for populated relations (e.g. github.com/strapi/strapi/issues/25746).\n //\n // Future direction: add `status` / `hasPublishedVersion` to GraphQL args on nested\n // to-many (and to-one) relation fields when the *target* content type has D&P, instead\n // of relying on root-level “context” that is easy to misread (args on User affecting\n // Articles). That would allow different publication settings per relation branch, match\n // how developers think about the graph, and let non-DP roots drop these args if desired.\n // Would require extending getContentTypeArgs(..., { isNested: true }) for D&P targets\n // and teaching association.ts to honor args.hasPublishedVersion on nested fields, not\n // only root inheritance.\n const publicationArgs = {\n status: args.PublicationStatusArg,\n hasPublishedVersion: args.HasPublishedVersionArg,\n };\n\n // Collection Types\n if (kind === 'collectionType') {\n if (!multiple) {\n return {\n documentId: nonNull(idArg()),\n ...publicationArgs,\n };\n }\n\n const params: Record<string, unknown> = {\n filters: naming.getFiltersInputTypeName(contentType),\n pagination: args.PaginationArg,\n sort: args.SortArg,\n };\n\n if (!isNested) {\n Object.assign(params, publicationArgs);\n }\n\n return params;\n }\n\n // Single Types\n if (kind === 'singleType') {\n const params: Record<string, unknown> = {};\n\n if (!isNested) {\n Object.assign(params, publicationArgs);\n }\n\n return params;\n }\n },\n\n /**\n * Filter an object entries and keep only those whose value is a unique scalar attribute\n */\n getUniqueScalarAttributes(attributes: Struct.SchemaAttributes) {\n const { isStrapiScalar } = getService('utils').attributes;\n\n const uniqueAttributes = entries(attributes).filter(\n ([, attribute]) => isStrapiScalar(attribute) && 'unique' in attribute && attribute.unique\n );\n\n return Object.fromEntries(uniqueAttributes);\n },\n\n /**\n * Map each value from an attribute to a FiltersInput type name\n * @param {object} attributes - The attributes object to transform\n * @return {Object<string, string>}\n */\n scalarAttributesToFiltersMap(attributes: Struct.SchemaAttributes) {\n return mapValues((attribute) => {\n const { mappers, naming } = getService('utils');\n\n const gqlScalar = mappers.strapiScalarToGraphQLScalar(attribute.type);\n\n return naming.getScalarFilterInputTypeName(gqlScalar);\n }, attributes);\n },\n\n /**\n * Apply basic transform to GQL args\n */\n transformArgs(\n args: any,\n {\n contentType,\n usePagination = false,\n }: { contentType: Struct.ContentTypeSchema; usePagination?: boolean }\n ) {\n const { mappers } = getService('utils');\n const { config } = strapi.plugin('graphql');\n const { pagination = {}, filters = {} } = args;\n\n // Init\n const newArgs = omit(['pagination', 'filters'], args);\n\n // Pagination\n if (usePagination) {\n const defaultLimit: number = config('defaultLimit');\n const maxLimit: number = config('maxLimit');\n\n Object.assign(\n newArgs,\n withDefaultPagination(pagination, {\n maxLimit,\n defaults: {\n offset: { limit: defaultLimit },\n page: { pageSize: defaultLimit },\n },\n })\n );\n }\n\n // Filters\n if (args.filters) {\n Object.assign(newArgs, {\n filters: mappers.graphQLFiltersToStrapiQuery(filters, contentType),\n });\n }\n\n return newArgs;\n },\n };\n};\n"],"names":["withDefaultPagination","pagination","strapi","service","getService","plugin","getContentTypeArgs","contentType","multiple","isNested","naming","args","modelType","filters","getFiltersInputTypeName","PaginationArg","sort","SortArg","kind","publicationArgs","status","PublicationStatusArg","hasPublishedVersion","HasPublishedVersionArg","documentId","nonNull","idArg","params","Object","assign","getUniqueScalarAttributes","attributes","isStrapiScalar","uniqueAttributes","entries","filter","attribute","unique","fromEntries","scalarAttributesToFiltersMap","mapValues","mappers","gqlScalar","strapiScalarToGraphQLScalar","type","getScalarFilterInputTypeName","transformArgs","usePagination","config","newArgs","omit","defaultLimit","maxLimit","defaults","offset","limit","page","pageSize","graphQLFiltersToStrapiQuery"],"mappings":";;;;AAKA,MAAM,EAAEA,qBAAqB,EAAE,GAAGC,UAAAA;AAOlC,YAAe,CAAA,CAAC,EAAEC,MAAM,EAA2B,GAAA;AACjD,IAAA,MAAM,EAAEC,OAAAA,EAASC,UAAU,EAAE,GAAGF,MAAAA,CAAOG,MAAM,CAAC,SAAA,CAAA;IAE9C,OAAO;QACLC,kBAAAA,CAAAA,CACEC,WAA0B,EAC1B,EAAEC,QAAAA,GAAW,IAAI,EAAEC,QAAAA,G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,MAAAA,CAAOG,MAAM,CAAC,SAAA,CAAA;YACjC,MAAM,EAAEJ,aAAa,EAAE,EAAEY,OAAAA,GAAU,EAAE,EAAE,GAAGF,IAAAA;;AAG1C,YAAA,MAAMsC,UAAUC,IAAAA,CAAK;AAAC,gBAAA,YAAA;AAAc,gBAAA;aAAU,EAAEvC,IAAAA,CAAAA;;AAGhD,YAAA,IAAIoC,aAAAA,EAAe;AACjB,gBAAA,MAAMI,eAAuBH,MAAAA,CAAO,cAAA,CAAA;AACpC,gBAAA,MAAMI,WAAmBJ,MAAAA,CAAO,UAAA,CAAA;AAEhCpB,gBAAAA,MAAAA,CAAOC,MAAM,CACXoB,OAAAA,EACAjD,qBAAAA,CAAsBC,UAAAA,EAAY;AAChCmD,oBAAAA,QAAAA;oBACAC,QAAAA,EAAU;wBACRC,MAAAA,EAAQ;4BAAEC,KAAAA,EAAOJ;AAAa,yBAAA;wBAC9BK,IAAAA,EAAM;4BAAEC,QAAAA,EAAUN;AAAa;AACjC;AACF,iBAAA,CAAA,CAAA;AAEJ,YAAA;;YAGA,IAAIxC,IAAAA,CAAKE,OAAO,EAAE;gBAChBe,MAAAA,CAAOC,MAAM,CAACoB,OAAAA,EAAS;oBACrBpC,OAAAA,EAAS4B,OAAAA,CAAQiB,2BAA2B,CAAC7C,OAAAA,EAASN,WAAAA;AACxD,iBAAA,CAAA;AACF,YAAA;YAEA,OAAO0C,OAAAA;AACT,QAAA;AACF,KAAA;AACF,CAAA;;;;"}
|
|
@@ -3,7 +3,7 @@ import { type ApolloServerPlugin } from '@apollo/server';
|
|
|
3
3
|
import type { Core } from '@strapi/types';
|
|
4
4
|
import type { BaseContext } from 'koa';
|
|
5
5
|
type StrapiGraphQLContext = BaseContext & {
|
|
6
|
-
|
|
6
|
+
rootQueryArgsByPath?: Map<string | number, Record<string, unknown>>;
|
|
7
7
|
};
|
|
8
8
|
export declare const determineLandingPage: (strapi: Core.Strapi) => ApolloServerPlugin<StrapiGraphQLContext>;
|
|
9
9
|
export declare function bootstrap({ strapi }: {
|
|
@@ -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;AAE1C,OAAO,KAAK,EAAE,WAAW,EAA8C,MAAM,KAAK,CAAC;AAUnF,KAAK,oBAAoB,GAAG,WAAW,GAAG;IACxC,
|
|
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;AAE1C,OAAO,KAAK,EAAE,WAAW,EAA8C,MAAM,KAAK,CAAC;AAUnF,KAAK,oBAAoB,GAAG,WAAW,GAAG;IACxC,mBAAmB,CAAC,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACrE,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,iBAwKlE"}
|
|
@@ -4,7 +4,7 @@ declare const _default: ({ strapi }: Context) => {
|
|
|
4
4
|
buildAssociationResolver({ contentTypeUID, attributeName, }: {
|
|
5
5
|
contentTypeUID: Internal.UID.ContentType;
|
|
6
6
|
attributeName: string;
|
|
7
|
-
}): (parent: any, args
|
|
7
|
+
}): (parent: any, args: any, context: any, info: any) => Promise<any>;
|
|
8
8
|
};
|
|
9
9
|
export default _default;
|
|
10
10
|
//# sourceMappingURL=association.d.ts.map
|
|
@@ -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,
|
|
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,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG;;AAhCnE,wBAiLE"}
|
|
@@ -24,7 +24,7 @@ declare const _default: (context: Context) => {
|
|
|
24
24
|
buildAssociationResolver({ contentTypeUID, attributeName, }: {
|
|
25
25
|
contentTypeUID: `admin::${string}` | `strapi::${string}` | `api::${string}.${string}` | `plugin::${string}.${string}`;
|
|
26
26
|
attributeName: string;
|
|
27
|
-
}): (parent: any, args
|
|
27
|
+
}): (parent: any, args: any, context: any, info: any) => Promise<any>;
|
|
28
28
|
};
|
|
29
29
|
export default _default;
|
|
30
30
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/plugin-graphql",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.46.0",
|
|
4
4
|
"description": "Adds GraphQL endpoint with default API methods.",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@koa/cors": "5.0.0",
|
|
66
66
|
"@strapi/design-system": "2.2.0",
|
|
67
67
|
"@strapi/icons": "2.2.0",
|
|
68
|
-
"@strapi/utils": "5.
|
|
68
|
+
"@strapi/utils": "5.46.0",
|
|
69
69
|
"graphql": "^16.8.1",
|
|
70
70
|
"graphql-depth-limit": "^1.1.0",
|
|
71
71
|
"graphql-playground-middleware-koa": "^1.6.21",
|
|
@@ -77,19 +77,19 @@
|
|
|
77
77
|
"pluralize": "8.0.0"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@strapi/strapi": "5.
|
|
81
|
-
"@strapi/types": "5.
|
|
80
|
+
"@strapi/strapi": "5.46.0",
|
|
81
|
+
"@strapi/types": "5.46.0",
|
|
82
82
|
"@types/graphql-depth-limit": "1.1.5",
|
|
83
83
|
"@types/koa-bodyparser": "4.3.12",
|
|
84
84
|
"@types/koa__cors": "5.0.0",
|
|
85
85
|
"cross-env": "^7.0.3",
|
|
86
|
-
"eslint-config-custom": "5.
|
|
86
|
+
"eslint-config-custom": "5.46.0",
|
|
87
87
|
"koa": "2.16.4",
|
|
88
88
|
"react": "18.3.1",
|
|
89
89
|
"react-dom": "18.3.1",
|
|
90
90
|
"react-router-dom": "6.30.3",
|
|
91
91
|
"styled-components": "6.1.8",
|
|
92
|
-
"tsconfig": "5.
|
|
92
|
+
"tsconfig": "5.46.0",
|
|
93
93
|
"typescript": "5.4.5"
|
|
94
94
|
},
|
|
95
95
|
"peerDependencies": {
|