Menu Close
    Start a Project Request quote Reading list Switch to dark mode
    magento-hyperlocal-marketplace-guide

    GraphQl implementation in Magento2

    What is GraphQl –  GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API.Using GraphQL we create own schema which is organized in terms of types and fields.GraphQL uses types to ensure channel only ask for what’s possible and provide clear and helpful errors.

    This blog assumes your familiarity with GraphQL concepts. If it is not the case – first learn about GraphQL on the official website or you can read our previous blog How to use GraphQL in php.

    Note :- GraphQL included in Magento 2.3.0 

    For implementing GraphQL in magento2 you have to create following files :-

    1 – create this file for register your module app/code/Test/TestGraphQl/registration.php


    2 – For define module name you have to create app/code/Test/TestGraphQl/etc/module.xml


    3 – First we have to define Schema of  query.In this part we mention that which fields and which type of data return in response.The schema is a container of your type hierarchy, which accepts root types in a constructor and provides methods for receiving information about your types to internal GrahpQL tools.The schema consists of two root types:

    • Query type is a surface of your read API
    • Mutation type (optional) exposes write API by declaring all possible mutations in your app

    In this blog we learn about only Query type.

    create schema.graphqls at this path app/code/Test/TestGraphQl/etc/


    4 – Create Resolver Model class which is define in schema.In this resolve method we simply return data of login customer.


    Please run following command to install this module.

    1 – php bin/magento setup:upgrade

    2 – php bin/magento cache:flush

    You can check your GraphQL query response by installing chrome extension ChromeiQL.

    For checking your query first you have to set endpoint.

    <magento root url>/graphql

    Magento use GraphQL module to manage all predefined or custom GraphQL queries.

    After set your endpoint you can see your custom query under section of document explorer.

    Mean while Please try the above example and If you have any Query then please feel free to put it in comment section.

    . . .

    Comments (2)

    Add Your Comment

  • vishal
    where to define schema in document doesn’t mention
    • Shubham Sharma
      Hello Vishal,
      Crete schema.graphqls at this path app/code/Test/TestGraphQl/etc/
  • Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close