0.0.8 • Published 8 months ago

@weipa/gql-linq-like-builder v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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

  1. Query
  2. Query (with variables)
  3. 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
        }
    }
}

↑ all examples

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
        }, 
    }
}

↑ all examples

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)

0.0.8

8 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.3

1 year ago

0.0.5

12 months ago

0.0.2

1 year ago

0.0.1

1 year ago