Hello,
I've created a plugin for the API project, that does a single field change, it works from the Playground.
The same code in the admin panel leads to the error "GraphQL error: Cannot query field "unpublishPage" on type "CmsMutation"."
Here is mutation :
mutation CmsCreatePage {
cms {
unpublishPage(page:"5dbc0261ab2ff702c2ecc196")
}
}
Here is plugin with typedef:
const pageFetcher = ctx => ctx.cms.entities.Page;
export default [
{
name: "cms-schema-page-unpublish",
type: "cms-schema",
typeDefs: '
extend type CmsMutation {
unpublishPage(
page: ID!
): Boolean
}
',
resolvers: {
CmsMutation: {
unpublishPage: unpublishPage(pageFetcher),
}
}
}
]
"webiny-cli": "^2.2.4",
Could you please suggest what I'm doing wrong? ^^
Hi @V1xel,
the code I'm seeing here looks a lot like the one found in older versions of Webiny. Not sure where you picked this up.
I can tell that based on two pieces in your code:
CmsMutation does not exist anymore, it's actually PbMutation ("Pb" = PageBuilder)pageFetcher. There is no entities key in context anymore.Not sure how this even works in GQL playground. Except you are on some older version of Webiny?
Anyhow, I'm actually creating a small example for you, which will show how to do this.
Please hold on!
Here are my API dependencies:
"webiny-api": "^1",
"webiny-api-cms": "^1",
"webiny-api-files": "^1",
"webiny-api-cookie-policy": "^1",
"webiny-api-google-tag-manager": "^1",
"webiny-api-mailchimp": "^1",
"webiny-api-security": "^1",
"webiny-app-cookie-policy": "^1",
"webiny-app-google-tag-manager": "^1",
"webiny-app-mailchimp": "^1",
"webiny-app-typeform": "^1",
"webiny-entity-mongodb": "^1",
"webiny-install": "^1",
"webiny-plugins": "^1"
Works in external graphql client also (Insomnia), but does not work in apollo chrome extension.
I already have another plugin(it is not mine), that I am using as an example, that is working even in the admin panel, but I can't figure out the difference.
If it is old, could you please provide old API documentation?
Ahh...
yes, this is definitely an old set of packages. All of our packages are currently starting with major version 2.
Can you check the mutation sent via browser (via Network tab), and compare it to the one sent via GQL playground? There must be a difference if one works, and the other does not.
API playground
{
"operationName": "UnpublishPage",
"variables": {},
"query": "mutation UnpublishPage {\n cms {\n unpublishPage(page: \"5dbc0261ab2ff702c2ecc196\")\n }\n}\n"
}
Admin panel
[
{
"operationName": "UnpublishPage",
"variables": {},
"query": "mutation UnpublishPage {\n cms {\n unpublishPage(page: \"5dbc0261ab2ff702c2ecc196\")\n __typename\n }\n}\n"
}
]
I don't understand how this happens yet.
Yes, this doesn't make sense :/
Sorry for asking, but the URLs on which you're posting these mutations are the same?
Thank you! Sorry for wasting your time, pulled env with dev server url. Everything works now.
Ahhh great @V1xel, I'm glad you got it resolved :)
Cheers!
Most helpful comment
Hi @V1xel,
the code I'm seeing here looks a lot like the one found in older versions of Webiny. Not sure where you picked this up.
I can tell that based on two pieces in your code:
CmsMutationdoes not exist anymore, it's actuallyPbMutation("Pb" = PageBuilder)pageFetcher. There is noentitieskey in context anymore.Not sure how this even works in GQL playground. Except you are on some older version of Webiny?
Anyhow, I'm actually creating a small example for you, which will show how to do this.
Please hold on!