Skip to content

Commit 2718033

Browse files
committed
Update the docs and readme
1 parent bb4cb0d commit 2718033

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ client = Client("https://countries.trevorblades.com")
4444

4545
This 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

4955
We 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
5258
response = 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
5870
query_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");
6072
response.data["countries"]
6173
# 1-element Vector{Any}:
6274
# Dict{String, Any}("name" => "Australia")
@@ -83,7 +95,7 @@ query_string = """
8395

8496
variables = 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
97109
end
98110
StructTypes.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

102114
response.data["countries"][1]
103115
# CountryName("Australia")
@@ -106,9 +118,9 @@ response.data["countries"][1]
106118
Or 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

113125
response.data["countries"][1]
114126
# Country
@@ -122,6 +134,7 @@ a mutation is doing something with an input. For example
122134

123135
```julia
124136
response = mutate(client, "mutation_name", Dict("new_id" => 1))
137+
response = mutate("mutation_name", Dict("new_id" => 1)) # Use global client
125138
```
126139

127140

docs/src/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ This will, by default, use a query to introspect the server schema, populating
3838
several fields of the `Client` object which can then be used to help with
3939
querying.
4040

41-
We can set a global client to be used by [`query`](@ref), [`mutate`](@ref), [`open_subscription`](@ref) and [`GraphQLClient.execute`](@ref).
41+
We can also set a global client to be user by queries, mutations, subscriptions and introspection functions.
4242

4343
```jldoctest client_intro
4444
julia> global_graphql_client(Client("https://countries.trevorblades.com"))
@@ -70,6 +70,9 @@ Now we have a `Client` object, we can query it without having to type a full
7070
GraphQL query by hand (note, you should be able to test these queries for yourself,
7171
thanks to [https://github.com/trevorblades/countries](https://github.com/trevorblades/countries)).
7272

73+
!!! info "Using the global `Client`"
74+
In these examples, if the `client` argument is omitted, the global client will be used instead.
75+
7376
```julia-repl
7477
julia> response = query(client, "countries")
7578
GraphQLClient.GQLResponse{Any}

0 commit comments

Comments
 (0)