Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Florian Engelhardt

November 12, 2019
Tweet

More Decks by Florian Engelhardt

Other Decks in Programming

Transcript

  1. 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. 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. HOW TO QUERY THAT HOW TO QUERY THAT { query

    { category(id: "id-of-category") { id title children { id title } } } } 8
  4. 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

  6. 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. BASIC EXAMPLE - TYPE BASIC EXAMPLE - TYPE /** *

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

    type Query { category(id: String!): Category } type Category { title: String! } 14
  9. BASIC EXAMPLE - QUERY BASIC EXAMPLE - QUERY { query

    { category (id: "42") { name } } } 15
  10. HOWTO USE THIS IN MY MODULE? HOWTO USE THIS IN

    MY MODULE? create a namespace mapper class 18
  11. 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. 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. 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. 22