45

Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business
Page 2: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 2© 2018 Magento, Inc.

Techinal Direction of

Magento

Page 3: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 3© 2018 Magento, Inc.

Anton KrilDirector of Architecture, Magento

@antonkril

Page 4: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 4© 2018 Magento, Inc.

• PWA using React

• Separation of APIs for storefront and admin

• Command & Query APIs

• Decoupling & modularity

• Cloud native

Tracks

Page 5: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 5© 2018 Magento, Inc.

• Evolutionary architecture

• Improved dev experience

• Leaner core, moving behavior to cloud

• Performance & scalability

Goals

Page 6: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 6© 2018 Magento, Inc.

Server

Business LayerPresentation

Layer

DB

Storefront

Admin

…Catalog Customers Checkout Order Management

Integrations

Page 7: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 7© 2018 Magento, Inc.

Server

Business LogicPresentation

Layer

DB

Storefront

Admin

…Catalog Customers Checkout Order Management

Integrations

Service

Contracts

Page 8: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 8© 2018 Magento, Inc.

Server

Storefront

Gateway

Storefront

Admin

Catalog Customers Checkout Order Management

Admin

Gateway

Integrations

Business Logic

DB

Service

Contracts

Query APIAggregation

Page 9: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 9© 2018 Magento, Inc.

Cloud

Order Service

Checkout Service

Catalog Service

Storefront

Gateway

Storefront

Admin

Catalog Customers Checkout Order Management

Admin

Gateway

Integrations

Customer Service

API

API

API

API

Query API

Page 10: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 10© 2018 Magento, Inc.

• Service Worker

• React-based storefront frontend (Admin stays the same)

• Redux for state management

• Webpack-based build system

• Layout-like customizations & modularity

Progressive Web App

http://bit.ly/pwa-studio-introduction

Page 11: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 11© 2018 Magento, Inc.

GraphQLFile: /vendor/magento/module-url-rewrite-graph-ql/etc/graphql.xml

<config>

<type xsi:type="OutputType" name="Query">

<field xsi:type="ObjectOutputField" name="urlResolver" type="EntityUrl"

resolver="Magento\UrlRewriteGraphQl\Model\Resolver\UrlRewrite">

<argument xsi:type="ScalarArgument" name="url" type="String" required="true"/>

</field>

</type>

<type xsi:type="OutputType" name="EntityUrl">

<field xsi:type="ScalarOutputField" name="id" type="Int" description="..."/>

<field xsi:type="ScalarOutputField" name="canonical_url" type="String" description="..."/>

<field xsi:type="ObjectOutputField" name="type" type="UrlRewriteEntityTypeEnum" description="..."/>

</type>

<type xsi:type="Enum" name="UrlRewriteEntityTypeEnum"/>

</config>

More details in the next talk

by Oleksii Korshenko

http://bit.ly/magento-graphql-preview-demo

Page 12: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 12© 2018 Magento, Inc.

Declarative DB Schema

<table name="catalog_product_entity">

<field name="entity_id">

<type>integer</type>

<unsigned>1</unsigned>

<primary>1</primary>

<identity>1</identity>

<comment>Entity ID</comment>

</field>

<field name=”price">

<type>integer</type>

<unsigned>1</unsigned>

<default>0</default>

</field>

</table>

<table name="catalog_product_entity">

<field name="entity_id">

<type>integer</type>

<unsigned>1</unsigned>

<primary>1</primary>

<identity>1</identity>

<comment>Entity ID</comment>

</field>

</table>

ALTER TABLE catalog_product_entity ADD COLUMN `price` int(11) unsigned DEFAULT NULL;

Page 13: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Resources

Page 14: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 14© 2018 Magento, Inc.

http://bit.ly/2-2-technical-guidelines

Page 15: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 15© 2018 Magento, Inc.

http://bit.ly/magento-versioning

Page 16: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 16© 2018 Magento, Inc.

https://12factor.net/

Page 17: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 17© 2018 Magento, Inc.

Page 18: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 18© 2018 Magento, Inc.

Magento 2 Web API

with GraphQL

Page 19: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 19© 2018 Magento, Inc.

Oleksii KorshenkoMagento 2 Architect, Community Engineering

Page 20: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Basic Components

Magento Web API

Page 21: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 21© 2018 Magento, Inc.

Current Web API Overview

• Backend Integrations which use Magento data

✓ Analytics

✓ Product Management

• Backend Integrations which Magento uses to do business

✓ Shipping

✓ Order management

• Headless Magento, Frontend integrations

✓ Advanced frontend (PWA)

Page 22: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 22© 2018 Magento, Inc.

Web API – Request Processing – High Level Overview

Page 23: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 23© 2018 Magento, Inc.

• /rest

– Handles all REST requests

– Supports JSON/XML

• /soap

– Used as entry points for SOAP requests

– Schema defined in WSDL

• /schema

– Schema generated in Swagger

– Schema generated in WSDL

Endpoints

Page 24: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 24© 2018 Magento, Inc.

Web API framework

👤

Shared

Page 25: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 25© 2018 Magento, Inc.

Configuration and Routing

<!-- Product Service -->

<route url="/V1/products" method="POST">

<service class="Magento\Catalog\Api\ProductRepositoryInterface" method="save"/>

<resources>

<resource ref="Magento_Catalog::products" />

</resources>

</route>

Page 26: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 26© 2018 Magento, Inc.

• ✅ POST should be used for entity(s) creation

• ✅ PUT should be used for entity(s) update

• ✅ PATCH should be used for patch entity(s) update (when unchanged

fields are omitted in the request)

• ✅ Must return responses with standard HTTP status codes

• ✅ Designed for system integrations, mobile app, one-page apps

• ✅ Supports tokens and cookies authentication

• ✅ OAuth 1.0 with token exchange

• ✅ Anonymous access

REST

Page 27: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 27© 2018 Magento, Inc.

• ✅ Designed for systems integration

• ✅ Token authentication for customers and admins

• ✅ Cookie authentication

• ✅ Anonymous access

• ✅ Schema WSDL

• ✅ Must return 200 HTTP status code in all cases. In case of exceptional

situation, error should be returned in the response

SOAP

Page 28: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 28© 2018 Magento, Inc.

Web API – Service Contracts

- Interfaces used for

data serialization/deserialization

- Stable interfaces

Page 29: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

GraphQL Frontend

Page 30: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 30© 2018 Magento, Inc.

Why GraphQL?

REST API

• One request per resource

• You always get all fields

• There is no way to deprecate

fields

• There is no way to know what

fields clients use

• There is no schema for the data

GraphQL

• Has strictly typed Schema

describing all data types and queries

• Documentation is a first class citizen

• Deprecation is a first class citizen

• IDE support

• There are clients for all major

languages. Javascript is

represented by Apollo, Relay, etc

Page 31: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 31© 2018 Magento, Inc.

GraphQL in Magento, Technical Vision

Page 32: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 32© 2018 Magento, Inc.

Web API – Request Processing – High Level Overview

Page 33: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 33© 2018 Magento, Inc.

Magento GraphQL - Demo

Page 34: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 34© 2018 Magento, Inc.

GraphQL. Multiple Queries

Page 35: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 35© 2018 Magento, Inc.

GraphQL Routing

Page 36: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 36© 2018 Magento, Inc.

Schema

Root type query: Query

Page 37: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 37© 2018 Magento, Inc.

Configuration and ExtensibilityFile: /vendor/magento/module-customer-graph-ql/etc/graphql.xml

<config …>

<type xsi:type="OutputType" name="Query">

<field xsi:type="ObjectOutputField"

name="customer"

type="Customer"

resolver="Magento\CustomerGraphQl\Model\Resolver\Customer”/>

</type>

<type xsi:type="OutputType" name="Customer">

<field xsi:type="ScalarOutputField" name="firstname" type="String" description="The customer's first name"/>

<field xsi:type="ScalarOutputField" name="middlename" type="String" description="The customer's middle name"/>

<field xsi:type="ScalarOutputField" name="lastname" type="String" description="The customer's family name"/>

<!--....-->

</type>

</config>

Page 38: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 38© 2018 Magento, Inc.

Configuration and ExtensibilityFile: /vendor/magento/module-url-rewrite-graph-ql/etc/graphql.xml

<config>

<type xsi:type="OutputType" name="Query">

<field xsi:type="ObjectOutputField" name="urlResolver" type="EntityUrl"

resolver="Magento\UrlRewriteGraphQl\Model\Resolver\UrlRewrite">

<argument xsi:type="ScalarArgument" name="url" type="String" required="true"/>

</field>

</type>

<type xsi:type="OutputType" name="EntityUrl">

<field xsi:type="ScalarOutputField" name="id" type="Int" description="..."/>

<field xsi:type="ScalarOutputField" name="canonical_url" type="String" description="..."/>

<field xsi:type="ObjectOutputField" name="type" type="UrlRewriteEntityTypeEnum" description="..."/>

</type>

<type xsi:type="Enum" name="UrlRewriteEntityTypeEnum"/>

</config>

Page 39: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 39© 2018 Magento, Inc.

• A resolver performs GraphQL request processing

• It is responsible for:

– constructing a query

– fetching data

– performing any calculations

– transforming the fetched and calculated data into a GraphQL array format

– finally, it returns the query results for rendering

Resolvers

Page 40: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 40© 2018 Magento, Inc.

SQL Mapping: GraphQL Query

Page 41: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 41© 2018 Magento, Inc.

SQL Mapping: SQL Query

Page 42: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 42© 2018 Magento, Inc.

SQL Result

Page 43: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 43© 2018 Magento, Inc.

GraphQL Response

Page 44: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 44© 2018 Magento, Inc.

Developer Tools. Chrome Extension

Page 45: Techinal Direction of · Current Web API Overview • Backend Integrations which use Magento data Analytics Product Management • Backend Integrations which Magento uses to do business

Page | 45© 2018 Magento, Inc.

Documentation

http://devdocs.magento.com/guides/v2.3/graphql/index.html

@okorshenko

Oleksii Korshenko

Magento 2 Architect,

Community Engineering

Thank You!