Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new API Mesh Custom Resolver sample. #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api-mesh/custom-resolver/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": [
"@babel/plugin-transform-react-jsx"
]
}
10 changes: 10 additions & 0 deletions api-mesh/custom-resolver/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"env": {
"es6": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:jest/recommended"],
"parserOptions": {
"ecmaVersion": "latest"
}
}
42 changes: 42 additions & 0 deletions api-mesh/custom-resolver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# package directories
node_modules
jspm_packages

# build
build
dist
.manifest-dist.yml

# Config
config.json
.env*
.aio

# Adobe I/O console config
console.json

# Test output
junit.xml

# IDE & Temp
.cache
.idea
.nyc_output
.vscode
coverage
.aws.tmp.creds.json
.wskdebug.props.tmp

# Parcel
.parcel-cache

# OSX
.DS_Store

# yeoman
.yo-repository

# logs folder for aio-run-detached
logs

91 changes: 91 additions & 0 deletions api-mesh/custom-resolver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# API Mesh Custom Resolver Example

This is an example for API Mesh custom resolver.

## Table of Contents

- [Introduction](#introduction)
- [Prerequisites](#prerequisites)
- [Explanation](#explanation)

## Introduction

Custom resolvers allow developers to extend the schema and apply some different business logic to the final result.

## Prerequisites

Before you begin, ensure you have the following:

- An Adobe Developer account
- Node.js and npm installed on your local machine (nvm 18.x.x (Mac/Linux) or nvm-windows (Windows))
- API Mesh configured for your project.

## Explanation

With this mesh config and custom resolver we can return two new fields, ```capital``` and ```currency```, to the final result. The data for these fields will be retrieved from Trevorblades GraphQl.

```graphql
{
ACOM_country(id: "US") {
available_regions {
code
id
name
}
full_name_english
full_name_locale
id
three_letter_abbreviation
two_letter_abbreviation
capital
currency
}
}
```

### Mesh configuration used in this example:

```json
{
"meshConfig": {
"sources": [
{
"name": "ACOMGQL",
"handler": {
"graphql": {
"endpoint": "https://venia.magento.com/graphql"
}
},
"transforms": [
{
"prefix": {
"includeRootOperations": true,
"value": "ACOM_"
}
}
]
},
{
"name": "TBGQL",
"handler": {
"graphql": {
"endpoint": "https://countries.trevorblades.com/graphql"
}
},
"transforms": [
{
"prefix": {
"includeRootOperations": true,
"value": "TB_"
}
}
]
}
],
"additionalTypeDefs": "extend type ACOM_Country { capital: String currency: String }",
"additionalResolvers": [
"./resolvers/cc-resolver.js"
]
}
}
```
3 changes: 3 additions & 0 deletions api-mesh/custom-resolver/app.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extensions:
dx/excshell/1:
$include: src/dx-excshell-1/api-mesh/ext.config.yaml
15 changes: 15 additions & 0 deletions api-mesh/custom-resolver/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Copyright 2024 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

jest.setTimeout(10000)

beforeEach(() => { })
afterEach(() => { })
Loading