GraphQL within OXID eShop

GraphQL within OXID eShop

#OXID_eSales
Ever wanted to create a GraphQL API within OXID eShop? The wait is over. We @OXID_eSales released the GraphQL-Base module which allowes you to create GraphQL queries and mutations in OXID.

https://github.com/OXID-eSales/graphql-base-module

8b8824ec70715f8599896375626c20d9?s=128

Florian Engelhardt

November 12, 2019
Tweet

Transcript

  1. 6.

    TIME FOR THEORY TIME FOR THEORY a query language for

    your API ask for what you need, get exactly that get many resources in a single request describe what’s possible with a type system 6
  2. 7.

    START WITH A SCHEMA DEFINITION START WITH A SCHEMA DEFINITION

    type Query { category(id: String!): Category } type Mutation { categoryCreate(category: Category!): Category } type Category { id: ID! title: String! articles: [Article] parent: Category siblings: [Category] children: [Category] } type Article { id: ID! title: String! category: Category } 7
  3. 8.

    HOW TO QUERY THAT HOW TO QUERY THAT { query

    { category(id: "id-of-category") { id title children { id title } } } } 8
  4. 9.

    WHAT DO YOU GET? WHAT DO YOU GET? { "data":

    { "category": { "id": "943a9ba3050e78b443c16e043ae60ef3", "title": "Kiteboarding", "children": [ { "id": "0f41a4463b227c437f6e6bf57b1697c4", "title": "Trapeze" }, { "id": "0f4f08358666c54b4fde3d83d2b7ef04", "title": "Kiteboards" } ] } } } 9
  5. 10.

    10

  6. 12.

    BASIC EXAMPLE - CONTROLLER BASIC EXAMPLE - CONTROLLER class CategoryController

    { /** * @Query() */ public function category(string $id): Category { // Some code that looks for a category and returns it. } } 12
  7. 13.

    BASIC EXAMPLE - TYPE BASIC EXAMPLE - TYPE /** *

    @Type() */ class Category { /** * @Field() */ public function getTitle(): string { return $this->title; } // ... } 13
  8. 14.

    BASIC EXAMPLE - THE SCHEMA BASIC EXAMPLE - THE SCHEMA

    type Query { category(id: String!): Category } type Category { title: String! } 14
  9. 15.

    BASIC EXAMPLE - QUERY BASIC EXAMPLE - QUERY { query

    { category (id: "42") { name } } } 15
  10. 19.

    HOWTO USE THIS IN MY MODULE? HOWTO USE THIS IN

    MY MODULE? create a namespace mapper class 18
  11. 20.

    HOWTO USE THIS IN MY MODULE? HOWTO USE THIS IN

    MY MODULE? create a namespace mapper class tag this class graphql_namespace_mapper in services.yaml 18
  12. 21.

    HOWTO USE THIS IN MY MODULE? HOWTO USE THIS IN

    MY MODULE? create a namespace mapper class tag this class graphql_namespace_mapper in services.yaml create a permission provider class 18
  13. 22.

    HOWTO USE THIS IN MY MODULE? HOWTO USE THIS IN

    MY MODULE? create a namespace mapper class tag this class graphql_namespace_mapper in services.yaml create a permission provider class tag this class graphql_permission_provider in services.yaml 18
  14. 24.
  15. 26.

    22