@weipa/gql-linq-like-builder
v0.0.8
Published
GraphQL Link-like-Builder
Downloads
5
Maintainers
Readme
GraphQL Linq-like-Builder
Angular library to generate GraphQL queries through the builder design pattern.
Install
npm install @weipa/gql-linq-like-builder --save
Usage
import { QueryBuilder } from "@weipa/gql-linq-like-builder";
let queryBuilder: QueryBuilder = new QueryBuilder(operation: string, isCollection: boolean);
Examples
- Query
- Query (with variables)
- Query (with nested fields selection)
Query:
import { QueryBuilder } from "@weipa/gql-linq-like-builder";
let queryBuilder: QueryBuilder = new QueryBuilder("user");
queryBuilder.AddColumn("id")
.AddColumn("name")
.AddColumn("surname");
let query: Query = queryBuilder.GetQuery();
console.log(query.ToString());
// Output
{
user
{
items {
id,
name,
surname
}
}
}
Query (with variables):
import { QueryBuilder } from "@weipa/gql-linq-like-builder";
let queryBuilder: QueryBuilder = new QueryBuilder("user");
queryBuilder.CreateFilter().AddCondition("id", MatchTypeEnum.EQUALS, 1);
queryBuilder.AddColumn("id")
.AddColumn("name")
.AddColumn("surname");
let query: Query = queryBuilder.GetQuery();
console.log(query.ToString());
// Output
{
user(where: {id: {
eq: 1
}})
{
items {
id,
name,
surname
},
}
}
Query (with nested fields selection):
import { QueryBuilder } from "@weipa/gql-linq-like-builder";
let queryBuilder: QueryBuilder = new QueryBuilder("user");
queryBuilder.AddColumn("id")
.AddColumn("name")
.AddColumn("surname")
.AddEntity("profile")
.AddColumn("id")
.AddColumn("description");
let query: Query = queryBuilder.GetQuery();
console.log(query.ToString());
// Output
{
user
{
items {
id,
name,
surname,
profile {
id,
description
}
},
}
}
Author
- Weipa Automation & Systems - GitHub
Contributors
If you are interested in actively maintaining / enhancing this project, get in touch.
- André Weiss - GitHub
- [YOUR NAME HERE] - Feel free to contribute to the codebase by resolving any open issues, refactoring, adding new features, writing test cases or any other way to make the project better and helpful to the community. Feel free to fork and send pull requests.
License
Copyright (c) 2023 Weipa https://weipa.com.br
The MIT License (http://www.opensource.org/licenses/mit-license.php)