Hi Siva!
The GraphQL schema is generally defined and publicly available here: https://github.com/commercetools/commercetools-api-reference/blob/main/api-specs/graphql/schema.sdl
If you want to play around and have a slightly more user friendly way of getting to know graphQL you may also want to check out the GraphQL IDE in Impex. (the schema can be found on the right hand side under Docs)
You can find the link to the respective regions here: https://docs.commercetools.com/docs/login
Europe GraphQL IDE can be found here for example: https://impex.europe-west1.gcp.commercetools.com/graphiql
Hope this helps.
Thanks @Jenny for the details. I have already checked this page https://github.com/commercetools/commercetools-api-reference/blob/main/api-specs/graphql/schema.sdl but I would like to know how can I create one custom graphql mutation. Can you please guide me on this that would be really helpful.
@Jenny Could you please help me on my previous comment ?
Hi @Siva
Below is an example of mutation to update a cart with multiple update actions. You can build such queries on the GraphQL IDE as Jenny mentioned above. Does this help?
mutation UpdateMyCart{
updateCart(
id: "9eg76th*******"
version: 5
actions: t
{
addLineItem: {
productId : "79847hlktsn*****",
variantId : 1,
quantity : 1
}
},
{
setCustomerEmail: {
email: ""
}
},
{
setShippingMethod: {
shippingMethod: {
id: "*****a125",
typeId: "shipping-method"
}
}
}
]
)
{
id
customerEmail
lineItems{
productId
productKey
variant{
sku
}
}
}
}
Hi @hetvim,
Thanks. I understand that we can use multiple actions in graphql request but still I think my question is not answered. I will try to elaborate it here:
Actually, I have understanding of Graphql as I have developed projects using Magento by graphql but in commercetools, I am totally new and learning now. I installed the php sdk in my local machine and also created a project in Merchant center. I explored, we have multiple graphqls available readily in commercetools and I checked that here but the question I have is whether we can create a new graphql query and mutation or not. Is there a provision in commercetools to do this ? If yes, where I need to create those files (Schema and Resolver) ? Because I cannot see such details in documentation and I need some understanding of those. Can you please help on these questions?
@hetvim @Jenny When I say new or custom graphql mutation, it may not available in GraphQL schema which is publicly available, https://github.com/commercetools/commercetools-api-reference/blob/main/api-specs/graphql/schema.sdl.
Example: updateCart is one of the default or built in graphql but if I want to create a complete new graphql mutation which have certain business logic, what steps I have to follow?
Hey @Siva,
to explain.a bit how GraphQL works within commercetools:
The GraphQL APIs are built on top of our REST APIs which are documented here: https://docs.commercetools.com/api/
Once an endpoint/action is made available via the REST API we try to make it available on GraphQL as well (which then will be seen in the public schema).
As our APIs need the mapping to be able to act on the calls made by GraphQL you can only use the calls that are part of the public schema, but they should cover pretty much everything that is available via the REST API as well. In case there is a difference feel free to reach out to Support (at support.commercetools.com) to log a suggestion to support the behaviour.
Hope that helps to clarify.
@Jenny Thanks for the detailed information. It helps.
Is that mean we can’t create a custom graphql mutation and we can only use the Graphql which are there in public schema?
Also, can’t we customize the behaviour of existing graphqls ?
Hey @Siva,
you can easily create a custom GraphQL mutation, but only as part of your services, not natively within the commercetools environment. The commercetools APIs are fixed for you.
In project implementations I am often seeing an integration layer in front of commercetools, combining data from various backend sources (commerce, CRM, ...). As part of this integration layer, you are free to define your own APIs, including GraphQL mutations.
E.g. Apollo Server is a good entry point: https://www.apollographql.com/docs/apollo-server/
Hi @Siva I believe that @Jenny and @Philipp Hofmann are correct, as of today the GraphQL API provided by commercetools is not prepared to host custom mutations, Implementing a super-graph on top of our API would allow you as Philipp mentions to gain control on the business logic that gets called. Maybe check also the concept of API Extensions, not exactly an answer to your original request, but could be a way to implement a workaround.
However the feedback is very welcome and this concept is something that we can discuss internally with the team in charge