@@ -117,14 +117,15 @@ npm install --save-dev purescript-graphql-client
117117```
118118
119119Then add a script to generate your schema on build. Run this script before compiling your purescript project.
120+
120121``` js
121- const { generateSchema } = require (' purescript-graphql-client' )
122+ const { generateSchema } = require (" purescript-graphql-client" );
122123
123124generateSchema ({
124- dir: ' ./src/generated' , // Where you want the generated code to go
125- modulePath: [' Generated' , ' Gql' ], // The name of the generated module
126- url: ' http://localhost:4892/graphql' , // Your GraphQL endpoint
127- })
125+ dir: " ./src/generated" , // Where you want the generated code to go
126+ modulePath: [" Generated" , " Gql" ], // The name of the generated module
127+ url: " http://localhost:4892/graphql" , // Your GraphQL endpoint
128+ });
128129```
129130
130131A full example can be seen in ` examples/2-codegen `
@@ -134,18 +135,22 @@ The full options for `generateSchema` can be seen in `codegen/schema/README.md`
134135You should run this script to build your schema as part of your build, before purescript compilation.
135136
136137If you wish to generate multiple schemas, use ` generateSchemas `
138+
137139``` js
138- const { generateSchemas } = require (' purescript-graphql-client' )
140+ const { generateSchemas } = require (" purescript-graphql-client" );
139141
140- generateSchemas ({
141- dir: ' ./src/generated' ,
142- modulePath: [' Generated' , ' Gql' ]
143- }, [
142+ generateSchemas (
144143 {
145- url: ' http://localhost:4892/graphql' ,
146- moduleName: ' MySchema' // The name of the module for this single schema
147- }
148- ])
144+ dir: " ./src/generated" ,
145+ modulePath: [" Generated" , " Gql" ],
146+ },
147+ [
148+ {
149+ url: " http://localhost:4892/graphql" ,
150+ moduleName: " MySchema" , // The name of the module for this single schema
151+ },
152+ ],
153+ );
149154```
150155
151156A full example can be seen in ` examples/2-codegen `
@@ -172,6 +177,7 @@ npm install --save @apollo/client
172177```
173178
174179you can then create a client using ` createClient ` . eg.
180+
175181``` purs
176182import MySchema (Query, Mutation)
177183import GraphQL.Client.BaseClients.Apollo (createClient)
@@ -195,8 +201,8 @@ import Type.Data.List (Nil')
195201 }
196202
197203```
198- Look in ` examples/4-mutation ` for a complete example.
199204
205+ Look in ` examples/4-mutation ` for a complete example.
200206
201207Use ` createSubscriptionClient ` if you want to make subscriptions. eg.
202208
@@ -243,7 +249,6 @@ You can see an examples of this in `examples/1-simple` and `e2e/1-affjax` .
243249
244250You can then write queries and mutations just as you would in the browser.
245251
246-
247252## Examples
248253
249254To view examples of what can be done with this library look at the ` examples ` and ` e2e ` directories.
@@ -255,6 +260,7 @@ API documentation can be found at https://pursuit.purescript.org/packages/puresc
255260## Guide
256261
257262### Query syntax
263+
258264Once you are set up and have generated your purescript schema. You can write your queries.
259265
260266The easiest way to do this is to go to https://gql-query-to-purs.herokuapp.com/query and paste your
@@ -292,6 +298,7 @@ As GraphQL arguments may have mixed types, the library provides tools to help ha
292298` ArgL ` and ` ArgR ` allow you to have different types for different code branches in arguments.
293299
294300eg.
301+
295302``` purs
296303let condition = true
297304
@@ -301,11 +308,13 @@ result <- query client "args_of_differing_types"
301308 { prop1, prop2 }
302309 }
303310```
311+
304312` IgnoreArg ` can be used to ignore both the label and value on a record.
305313
306314This is most commonly used with ` guardArg ` to ignore an argument property unless a condition is met.
307315
308316eg.
317+
309318``` purs
310319let condition = true
311320
@@ -320,6 +329,7 @@ GraphQL arrays can be written as purescript arrays if they are homogenous, but f
320329you can use ` AndArgs ` /` andArg ` or the ` +++ ` /` ++ ` operator.
321330
322331eg.
332+
323333``` purs
324334
325335result <- query client "mixed_args_query"
@@ -358,15 +368,22 @@ In a dynamic language you might fold a collection of users to create a graphql q
358368
359369``` gql
360370mutation myUpdates {
361- _1 : update_users (where : {id : 1 }, _set : { value : 10 }) { affected_rows }
362- _2 : update_users (where : {id : 2 }, _set : { value : 15 }) { affected_rows }
363- _3 : update_users (where : {id : 3 }, _set : { value : 20 }) { affected_rows }
371+ _1 : update_users (where : { id : 1 }, _set : { value : 10 }) {
372+ affected_rows
373+ }
374+ _2 : update_users (where : { id : 2 }, _set : { value : 15 }) {
375+ affected_rows
376+ }
377+ _3 : update_users (where : { id : 3 }, _set : { value : 20 }) {
378+ affected_rows
379+ }
364380}
365381```
366382
367383To do this in this library there is there is the ` Spread ` constructor that creates these aliases for you and decodes the response as an array.
368384
369385eg.
386+
370387``` purs
371388
372389import GraphQL.Client.Alias.Dynamic (Spread(..))
@@ -401,6 +418,7 @@ query client "widget_names_with_id_1"
401418 `withVars`
402419 { idVar: 1 }
403420```
421+
404422` withVars ` uses ` encodeJson ` to turn the variables in json. If you
405423wish to use a custom encoder, use ` withVarsEncode ` .
406424
@@ -415,7 +433,6 @@ Only top level directives, that have a query, mutation or subscription location
415433
416434Please look in the example/12-directives to see an example of this.
417435
418-
419436### Full responses
420437
421438If you wish to get the full response, as per the [ GraphQL Spec] ( https://spec.graphql.org/June2018/#sec-Response ) use the "FullRes" versions of the query functions
@@ -444,6 +461,7 @@ To see how these options work, I recommend looking at the [Apollo core docs](htt
444461The options are usually set using record updates or ` identity ` for default options.
445462
446463eg.
464+
447465``` purs
448466 mutationOpts _
449467 { update = Just update
458476
459477## Alternatives to this package
460478
461-
462479### [ purescript-graphql-fundeps] ( https://github.com/meeshkan/purescript-graphql-fundeps )
463480
464481A much more lightweight graphql client. This package does not infer query types and does not support subscriptions or caching but allows writing in
@@ -469,6 +486,7 @@ graphql syntax and has much less source code. Probably preferable if your query
469486A port of [ elm-graphql] ( https://github.com/dillonkearns/elm-graphql/ ) .
470487
471488Although the names and scope of the 2 packages are very similar they are not connected and there are a few differences:
489+
472490- This package uses record syntax to make queries whereas purescript-graphqlclient uses applicative/ado syntax
473491- This package allows use of Apollo if you wish (or other lower level graphQL clients)
474492- This package supports subscriptions, watch queries and client caching
0 commit comments