https://github.com/coryodaniel/federated-absinthe
Federating absinthe graphql with GraphQL Mesh.
https://github.com/coryodaniel/federated-absinthe
absinthe absinthe-graphql elixir graphql
Last synced: 4 months ago
JSON representation
Federating absinthe graphql with GraphQL Mesh.
- Host: GitHub
- URL: https://github.com/coryodaniel/federated-absinthe
- Owner: coryodaniel
- Created: 2021-08-27T20:25:06.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-29T17:24:35.000Z (almost 4 years ago)
- Last Synced: 2025-04-10T04:12:32.921Z (6 months ago)
- Topics: absinthe, absinthe-graphql, elixir, graphql
- Language: Elixir
- Homepage:
- Size: 127 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Federating Absinthe Elixir w/ GraphQL Mesh
Federating the Absinthe GraphQL elixir library with GraphQL Mesh.
## SetupMac OS Setup
```shell
brew install gpg asdf
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git
asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git
asdf install
```## Run GraphQL Mesh Example App
[GraphQL Mesh](https://github.com/Urigo/graphql-mesh) includes a [federation example](https://github.com/Urigo/graphql-mesh/tree/master/examples/federation-example) federating 4 nodejs graphs. This example replaces the `accounts` nodejs app with Absinthe.
```shell
yarn install
yarn start
```The example query should run successfully.
## How it works
The GraphQL Mesh config file `.meshrc.yml` contains a list of APIs that can be included in the mesh. GraphQL Mesh supports 12 API sources including GraphQL (with or without federation support), gRPC, OpenAPI, and others.
When adding a graphql source that does **not** support federation, a transform can be used.
Here is an example of extending the root query and allowing other fields to access the accounts' user fields.
```yaml
- name: accounts
handler:
graphql:
endpoint: http://localhost:9871/graphql
transforms:
- federation:
types:
- name: Query # Note: Absinthe defaults the root query type name to "RootQueryType"
config:
extend: true
- name: User
config:
keyFields:
- id
resolveReference:
queryFieldName: user
```The query name on line 8 of the YAML above needs to match the name of the root query in Absinthe.
```ex
query name: "Query" do
# ...
end
```