All Projects → youyo → gql-query-builder

youyo / gql-query-builder

Licence: MIT license
This is a GraphQL query builder.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to gql-query-builder

Php Graphql Client
A PHP library that simplifies the process of interacting with GraphQL API's by providing simple client and query generator classes.
Stars: ✭ 124 (+313.33%)
Mutual labels:  graphql-client, query-builder
elm-graphql
GraphQL made easy in Elm!
Stars: ✭ 56 (+86.67%)
Mutual labels:  graphql-client
database
A php class for managing and connecting to a database
Stars: ✭ 33 (+10%)
Mutual labels:  query-builder
kobby
Kobby is a codegen plugin of Kotlin DSL Client by GraphQL schema. The generated DSL supports execution of complex GraphQL queries, mutation and subscriptions in Kotlin with syntax similar to native GraphQL syntax.
Stars: ✭ 52 (+73.33%)
Mutual labels:  graphql-client
Gridify
Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.
Stars: ✭ 372 (+1140%)
Mutual labels:  query-builder
LiveGQL
Use GraphQL Subscriptions on iOS 👌
Stars: ✭ 84 (+180%)
Mutual labels:  graphql-client
indexeddb-orm
Indexed DB ORM
Stars: ✭ 53 (+76.67%)
Mutual labels:  query-builder
q-builders
Type safe database agnostic query builders.
Stars: ✭ 49 (+63.33%)
Mutual labels:  query-builder
py-graphql-client
Dead-simple GraphQL client with subscriptions over websockets
Stars: ✭ 36 (+20%)
Mutual labels:  graphql-client
python-graphql-client
Simple module for making requests to a graphQL server in python.
Stars: ✭ 65 (+116.67%)
Mutual labels:  graphql-client
kex
ORM-less for Knex
Stars: ✭ 17 (-43.33%)
Mutual labels:  query-builder
cqrs
A foundational package for Command Query Responsibility Segregation (CQRS) compatible with Laravel.
Stars: ✭ 37 (+23.33%)
Mutual labels:  query-builder
neo4j-graphql-java
Pure JVM translation for GraphQL queries and mutations to Neo4j's Cypher
Stars: ✭ 94 (+213.33%)
Mutual labels:  graphql-client
nim-graphql
Nim implementation of GraphQL with sugar and steroids
Stars: ✭ 47 (+56.67%)
Mutual labels:  graphql-client
graphql-typed-client
Strongly typed GraphQL client for .NET
Stars: ✭ 16 (-46.67%)
Mutual labels:  graphql-client
sea-query
🔱 A dynamic SQL query builder for MySQL, Postgres and SQLite
Stars: ✭ 595 (+1883.33%)
Mutual labels:  query-builder
query-filter
🔍 Database/Eloquent Query Builder filters for Laravel
Stars: ✭ 69 (+130%)
Mutual labels:  query-builder
aws-mobile-appsync-sdk-android
Android SDK for AWS AppSync.
Stars: ✭ 101 (+236.67%)
Mutual labels:  graphql-client
uri-query-parser
a parser and a builder to work with URI query string the right way in PHP
Stars: ✭ 38 (+26.67%)
Mutual labels:  query-builder
aql
asyncio query generator
Stars: ✭ 33 (+10%)
Mutual labels:  query-builder

gql-query-builder

This is a GraphQL query builder.
Use with method chain.

Install

pip install gql-query-builder

Usage

  • query
from gql_query_builder import GqlQuery

query = GqlQuery().fields(['name']).query('hero').operation().generate()
print(query)
"""
query {
    hero {
        name
    }
}
"""
  • mutation
from gql_query_builder import GqlQuery

query = GqlQuery().fields(['stars', 'commentary']).query('createReview', input={"episode": "$ep", "review": "$review"}).operation('mutation', name='CreateReviewForEpisode', input={"$ep": "Episode!", "$review": "ReviewInput!"}).generate()
print(query)
"""
mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
    createReview(episode: $ep, review: $review) {
        stars
        commentary
    }
}
"""

Methods

  • fields()
    build response fields.
#Syntax

fields(
    fields: List[str] = [],
    name: str = '',
    condition_expression: str = ''
)
  • query()
    build query fields.
#Syntax

query(
    name: str = '',
    alias: str = '',
    input: Dict[str, Union[str, int]] = {}
)
  • operation()
    build operation fields.
#Syntax

operation(
    query_type: str = 'query',
    name: str = '',
    input: Dict[str, Union[str, int]] = {},
    queries: List[str] = []
)
  • fragment()
    build fragment fields.
#Syntax

fragment(
    name: str,
    interface: str
)
  • generate()
    generate query.
#Syntax

generate()

Examples

  • Nesting fields
from gql_query_builder import GqlQuery

field_friends = GqlQuery().fields(['name'], name='friends').generate()
query = GqlQuery().fields(['name', field_friends]).query('hero').operation('query').generate()
print(query)
"""
query {
    hero {
        name
        friends {
            name
        }
    }
}
"""
  • Query with input
from gql_query_builder import GqlQuery

query = GqlQuery().fields(['name', 'height']).query('human', input={"id": '"1000"'}).operation().generate()
print(query)
"""
query {
    human(id: "1000") {
        name
        height
    }
}
"""
  • Query with nested input
from gql_query_builder import GqlQuery
GqlQuery().fields(['name', 'height']).query('human', input={"input": {"data": {"id": "1000", "name": "test"}}}).operation().generate()
"""
query{
    human(input: {data: {id: "1000", name: "test"}}){
        human{
            name, 
            height
        }
    }
}
"""
  • Query with input and arguments
from gql_query_builder import GqlQuery

query = GqlQuery().fields(['name', 'height(unit: FOOT)']).query('human', input={"id": '"1000"'}).operation().generate()
print(query)
"""
query {
    human(id: "1000") {
        name
        height(unit: FOOT)
    }
}
"""
  • Alias
from gql_query_builder import GqlQuery

query_empirehero = GqlQuery().fields(['name']).query('hero', alias='empireHero', input={"episode": 'EMPIRE'}).generate()
query_jedihero = GqlQuery().fields(['name']).query('hero', alias='jediHero', input={"episode": 'JEDI'}).generate()
query = GqlQuery().operation('query', queries=[query_empirehero, query_jedihero]).generate()
print(query)
"""
query {
    empireHero: hero(episode: EMPIRE) {
        name
    }
    jediHero: hero(episode: JEDI) {
        name
    }
}
"""
  • Fragments
from gql_query_builder import GqlQuery

field_friends = GqlQuery().fields(['name'], name='friends').generate()
query = GqlQuery().fields(['name', 'appearsIn', field_friends]).fragment('comparisonFields', 'Character').generate()
print(query)
"""
fragment comparisonFields on Character {
    name
    appearsIn
    friends {
        name
    }
}
"""
  • Refer to fragments
from gql_query_builder import GqlQuery

query_leftComparison = GqlQuery().fields(['...comparisonFields']).query('hero', alias='leftComparison', input={"episode": "EMPIRE"}).generate()
query_rightComparison = GqlQuery().fields(['...comparisonFields']).query('hero', alias='rightComparison', input={"episode": "JEDI"}).generate()
query = GqlQuery().operation('query', queries=[query_leftComparison, query_rightComparison]).generate()
print(query)
"""
query {
    leftComparison: hero(episode: EMPIRE) {
        ...comparisonFields
    }
    rightComparison: hero(episode: JEDI) {
        ...comparisonFields
    }
}
"""
  • Query with variables
from gql_query_builder import GqlQuery

field_friends = GqlQuery().fields(['name'], name='friends').generate()
query = GqlQuery().fields(['name', field_friends]).query('hero', input={"episode": "$episode"}).operation('query', name='HeroNameAndFriends', input={"$episode": "Episode"}).generate()
print(query)
"""
query HeroNameAndFriends($episode: Episode) {
    hero(episode: $episode) {
        name
        friends {
            name
        }
    }
}
"""
  • Directives
from gql_query_builder import GqlQuery

field_friends = GqlQuery().fields(['name'], name='friends @include(if: $withFriends)').generate()
query = GqlQuery().fields(['name', field_friends]).query('hero', input={"episode": "$episode"}).operation('query', name='Hero', input={"$episode": "Episode", "$withFriends": "Boolean!"}).generate()
print(query)
"""
query Hero($episode: Episode, $withFriends: Boolean!) {
    hero(episode: $episode) {
        name
        friends @include(if: $withFriends) {
            name
        }
    }
}
"""
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].