Skip to content
5.0 Upwork, 100+ reviews Adobe Certified since 2021 New: become your own Magento developer Learn more →

Recipe for adding a GraphQL mutation that hits an existing service contract?

Goal: expose VendorRepositoryInterface::save as a createVendor(input: VendorInput!): Vendor mutation. Files: etc/schema.graphqls (input type, payload type, mutation), Model/Resolver/CreateVendor.php (implements ResolverInterface, calls the repository, maps VendorInterface to the GraphQL output array). Auth: add @doc on the mutation and gate via the resolver checking $context->getExtensionAttributes()->getIsCustomer() for storefront-only. Verify: bin/magento cache:clean config graphql_query_resolver_cache, then run the mutation in a GraphQL IDE with a customer token. The resolver should be < 30 lines, if it's longer, business logic leaked out of the repository.

Was this helpful?
Kishan Savaliya Online 10 AM to 7 PM IST Chat on WhatsApp