Package: gql-ext
GraphQL FacadeGraphQL Facade is a python application-intermediary between a
frontend application using GraphQL and a REST application on the backend
oriented declarative style of the description of the services.GraphQL Facade allowmake a requests to the REST service using GraphQL languageuse batch loading (subject to the rules)Adding new REST service to the ApplicationTo add a new service, you need to perform several steps:create a description of the data schema ingraphql syntaxcreateREST service description(yaml or json supported)describeresolvers(yaml or json)addschema descriptionto main configuration filespecify the Base Url of the service in the application settingsREST service description<service_name>: 
    <endpoint_name>:
        method: <METHOD>
        path: <PATH>service_name: Name of your REST API service.endpoint_name: Name of your REST endpoint.method: GET, POST, PATCH, PUT, DELETE (GET default)path: path to yor endpointResolvers<Parent_name.field_name>:
    endpoint: <service_name.endpoint_name>
    batch: True
    args:
        <param_name>: <param_value>
    loader: <path.to.your.custom.resolver_file.resolver_name>Parent_name.field_name: field name in your graphql schema (Query.namefor example)endpoint: your rest endpoint for this data field inservice_name.endpoint_nameformatloader: path to custom resolver (not a required field). Use python site-packages syntaxargs: if you want to use any params to make request to REST you can set args field.param_name- an arbitrary name of the variable,param_value- arbitrary value.
To use the attributes of a parent element, useparent.the prefix and then the name of the attribute.
for examlepost_is: parent.idbatch: usebatch loading. False by defaultSchemas descriptionschemas:
  <schema_name>:
    url: <schema_url>
    resolvers: <path/to/your/resolvers/file>
    sdl:
      - <list/of/paths/to/sdl/directories>
      - <or/and/sdl/files>

rest:
  - <list/of/paths/to/your/rest/description/files>schema_name: your schema nameurl: url to graphql endpoint (by default equal to schema name)resolvers: path (relative to base directory) to your resolvers filesdl: list of paths to.graphqlfiles (schema descriptions) or directories with.graphqlfilesrest: list of paths to rest definition files (relative to base directory)REST App connection ExampleLet's say you have a REST service with signature:
Input:{
    id: [0, 1, 2],
    q: "any search string"
}Output:{
  "pagination": {
    "total": 0,
    "offset": 0,
    "limit": 0
  },
  "result": [
    {
      "conditions": {},
      "calculator_id": 0,
      "version": 0,
      "created": "2019-08-29T09:09:23.048Z",
      "terms": [
        0
      ],
      "status": "archive",
      "updated": "2019-08-29T09:09:23.048Z",
      "amounts": [
        0
      ],
      "priority": 0,
      "title": "string",
      "meta": {},
      "id": 0
    }
  ]
}for connect your api to GraphQL facade follow that steps:previewAs a result of all the steps we get the structure (files and directories that we will not use are omitted)-app
    -graphql
        -calculator
            -sdl
                mutation.graphql
                query.graphql
            loaders.py
            resolvers.yaml
            rest.yaml
        ...
    init_facade.yaml
    ...
....graphqlfiles - description of your data schemaloaders.pycustom resolvers (if you need)resolvers.yamldescription of resolversrest.yamldescription of rest api serviceinit_facade.yamldescription all schemas and file paths for schemathe file scheme is conditional and not mandatory but it is recommended to adhere to this rule of file location and naming1. describe data schemathe data schema describes data types and arguments
for our REST service it will have the following formapp/graphql/calculator/sdl/query.graphqltype Query {
    calculators(id: [Int], q: String): Calculators
    }

type Calculators{
    pagination: Pagination
    result: [Calculator]
    }

type Calculator {
    id: Int
    created: String
    updated: String
    calculator_id: Int
    status: String
    version: Int
    title: String
    amounts: [String]
    terms: [Int]
    meta: String
    priority: Int
    conditions: String
    }

type Pagination {
    total: Int
    limit: Int
    offset: Int
    }2. REST service descriptionREST description files contains information about paths to your REST handlersfor our API:app/graphql/calculator/rest.json{
  "calculator": {
    "find_calculators": {
      "method": "GET",
      "path": "/api/v1/pdl_calculators/"
    }
}3. describe resolversResolvers files explain how to receive Schema fields
(which REST handler to use, whether to use bath loading or smth else)app/graphql/calculator/resolvers.json{
  "Query.calculators": {
    "endpoint": "calculator.find_calculators"
  }
}4. main configuration fileapp/init_facade.yamlConfiguration file describe file location for our schemaschemas:

  calculator:
    url: calculator
    resolvers: app/graphql/calculator/resolvers
    sdl:
      - app/graphql/calculator/sdl

rest:
  - app/graphql/calculator/rest5. base url to configIt is important not to forget to specify URLs in the application settings
We do not specify base_url in yaml or json files to be able to pass base_url as environment variablesKey must match to REST service name in rest.yaml filesettings/config.pyclass Config:
...
    BASE_URLS = {
                 ...
                 'calculator': env.str('calculator_api', default='http:/calculator.prod.com')
                 ...
                }
...Batch loadingFor use batch loading you must follow few simple rules:REST API endpoint must accept a list ofidargumentsREST must return list of records (which perform a conditions of a request) inresultfield and sendidfield to each rowfor example:{
  "pagination": {
    "total": 2,
    "limit": 10,
    "offset": 0
  },
  "result": [
    {
      "id": 1
    },
    {
      "id": 2
    }
  ],
  "success": true
}finally setbatch=Truein your fields resolver description:Calculator.calculator:
    endpoint: /api/v1/calculator
    batch: True