Build GraphQL documents from simple Elixir data structures.
The goal of GraphQLDocument is to give the developer superpowers when it comes to writing GraphQL document strings in Elixir.
Using the functions in this library, developers can:
- Build documents programmatically, enabling higher level tooling and DSLs.
- Compose separate chunks of GraphQL documents together with ease.
- Dynamically build GraphQL documents on the fly. (For example, including or excluding sections.)
The complete documentation for GraphQLDocument is located here.
Add :graphql_document
as a dependency in mix.exs
:
def deps do
[
{:graphql_document, "~> 0.2.2"}
]
end
The following call to GraphQLDocument.query(...)
will generate the GraphQL
string below.
query(
[
customer: {[id: var(:customerId)], [
:name,
:email,
phoneNumbers: field(args: [type: MOBILE]),
cartItems: [
:costPerItem,
...: :cartDetails
]
]}
],
variables: [customerId: Int],
fragments: [cartDetails: {
on(CartItem),
[:sku, :description, :count]
}]
)
query ($customerId: Int) {
customer(id: $customerId) {
name
email
phoneNumbers(type: MOBILE)
cartItems {
costPerItem
...cartDetails
}
}
}
fragment cartDetails on CartItem {
sku
description
count
}
For more information on syntax and features, read the docs here.
Copyright 2022 United Community Bank
Licensed 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 CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.