From b96ba4738124f074e06061833092d1ec858345e4 Mon Sep 17 00:00:00 2001 From: Denis Artyushin Date: Thu, 23 Mar 2023 16:28:21 +0300 Subject: [PATCH 1/2] Added graphql-query to content --- .../python/client/graphql-query.md | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/content/code/language-support/python/client/graphql-query.md diff --git a/src/content/code/language-support/python/client/graphql-query.md b/src/content/code/language-support/python/client/graphql-query.md new file mode 100644 index 0000000000..b6fc56658f --- /dev/null +++ b/src/content/code/language-support/python/client/graphql-query.md @@ -0,0 +1,103 @@ +--- +name: graphql-query +description: Complete GraphQL query string generation for python.. +url: https://github.com/denisart/graphql-query +github: denisart/graphql-query +--- + +**graphql_query** is complete GraphQL query string builder for python. With **graphql_query** +you can The documentation for **graphql_query** can be found at [https://denisart.github.io/graphql-query/](https://denisart.github.io/graphql-query/). + +``` +$ pip install graphql_query +``` + +Code for the simple query + +```graphql +{ + hero { + name + } +} +``` + +it is + +```python +from graphql_query import Operation, Query + +hero = Query(name="hero", fields=["name"]) +operation = Operation(type="query", queries=[hero]) + +print(operation.render()) +""" +query { + hero { + name + } +} +""" +``` + +For generation of the following query + +```graphql +query Hero($episode: Episode, $withFriends: Boolean!) { + hero(episode: $episode) { + name + friends @include(if: $withFriends) { + name + } + } +} +``` + +we have + +```python +from graphql_query import Argument, Directive, Field, Operation, Query, Variable + +episode = Variable(name="episode", type="Episode") +withFriends = Variable(name="withFriends", type="Boolean!") + +arg_episode = Argument(name="episode", value=episode) +arg_if = Argument(name="if", value=withFriends) + +hero = Query( + name="hero", + arguments=[arg_episode], + fields=[ + "name", + Field( + name="friends", + fields=["name"], + directives=[Directive(name="include", arguments=[arg_if])] + ) + ] +) +operation = Operation( + type="query", + name="Hero", + variables=[episode, withFriends], + queries=[hero] +) +print(operation.render()) +""" +query Hero( + $episode: Episode + $withFriends: Boolean! +) { + hero( + episode: $episode + ) { + name + friends @include( + if: $withFriends + ) { + name + } + } +} +""" +``` From 45740139a68d1755b3e54b92afe4d54d717c9cbf Mon Sep 17 00:00:00 2001 From: Denis Artyushin Date: Thu, 23 Mar 2023 17:39:09 +0300 Subject: [PATCH 2/2] Added doc URL for graphql-query --- .../code/language-support/python/client/graphql-query.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/code/language-support/python/client/graphql-query.md b/src/content/code/language-support/python/client/graphql-query.md index b6fc56658f..3f1d4e80b9 100644 --- a/src/content/code/language-support/python/client/graphql-query.md +++ b/src/content/code/language-support/python/client/graphql-query.md @@ -1,7 +1,7 @@ --- name: graphql-query -description: Complete GraphQL query string generation for python.. -url: https://github.com/denisart/graphql-query +description: Complete GraphQL query string generation for python. +url: https://denisart.github.io/graphql-query/ github: denisart/graphql-query ---