@@ -44,6 +44,12 @@ client = Client("https://countries.trevorblades.com")
4444
4545This will, by default, use a query to introspect the server schema.
4646
47+ We can also set a global client to be user by queries, mutations, subscriptions and introspection functions.
48+
49+ ``` julia
50+ global_graphql_client (Client (" https://countries.trevorblades.com" ))
51+ ```
52+
4753### Querying
4854
4955We can query a ` client ` without having to type a full GraphQL query by hand, with the response containing fields obtained by introspection
@@ -52,11 +58,17 @@ We can query a `client` without having to type a full GraphQL query by hand, wit
5258response = query (client, " countries" )
5359```
5460
55- We can add arguments and speciy fields in the response
61+ Or we can query the global client
62+
63+ ``` julia
64+ response = query (" countries" )
65+ ```
66+
67+ We can add arguments and specify fields in the response
5668
5769``` julia
5870query_args = Dict (" filter" => Dict (" code" => Dict (" eq" => " AU" )))
59- response = query (client, " countries" ; query_args= query_args, output_fields= " name" );
71+ response = query (" countries" ; query_args= query_args, output_fields= " name" );
6072response. data[" countries" ]
6173# 1-element Vector{Any}:
6274# Dict{String, Any}("name" => "Australia")
@@ -83,7 +95,7 @@ query_string = """
8395
8496variables = Dict (" eq" => " AU" )
8597
86- response = GraphQLClient. execute (client, query_string, variables= variables)
98+ response = GraphQLClient. execute (query_string, variables= variables)
8799```
88100
89101
@@ -97,7 +109,7 @@ struct CountryName
97109end
98110StructTypes. StructType (:: Type{CountryName} ) = StructTypes. OrderedStruct ()
99111
100- response = query (client, " countries" , Vector{CountryName}, query_args= query_args, output_fields= " name" )
112+ response = query (" countries" , Vector{CountryName}, query_args= query_args, output_fields= " name" )
101113
102114response. data[" countries" ][1 ]
103115# CountryName("Australia")
@@ -106,9 +118,9 @@ response.data["countries"][1]
106118Or we can use introspection to build the type automatically
107119
108120``` julia
109- Country = GraphQLClient. introspect_object (client, " Country" )
121+ Country = GraphQLClient. introspect_object (" Country" )
110122
111- response = query (client, " countries" , Vector{Country}, query_args= query_args, output_fields= " name" )
123+ response = query (" countries" , Vector{Country}, query_args= query_args, output_fields= " name" )
112124
113125response. data[" countries" ][1 ]
114126# Country
@@ -122,6 +134,7 @@ a mutation is doing something with an input. For example
122134
123135``` julia
124136response = mutate (client, " mutation_name" , Dict (" new_id" => 1 ))
137+ response = mutate (" mutation_name" , Dict (" new_id" => 1 )) # Use global client
125138```
126139
127140
0 commit comments