Skip to content

Commit 5f3a8f7

Browse files
committed
Merge branch 'main' of https://github.com/OxfordAbstracts/purescript-graphql-client into remove-ArgGql-from-genned-schema-#102
2 parents f52a25c + 677b04a commit 5f3a8f7

File tree

116 files changed

+8100
-4524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+8100
-4524
lines changed

Diff for: .DS_Store

6 KB
Binary file not shown.

Diff for: README.md

+24-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ main =
4141
-- Run gql query
4242
queryGql ::
4343
forall query returns.
44-
GqlQuery Schema query returns =>
44+
GqlQuery Nil' OpQuery Schema query returns =>
4545
DecodeJson returns =>
4646
String -> query -> Aff returns
4747
queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Schema)
@@ -182,9 +182,11 @@ import MySchema (Query, Mutation)
182182
import GraphQL.Client.BaseClients.Apollo (createClient)
183183
import GraphQL.Client.Query (query)
184184
import GraphQL.Client.Types (Client)
185+
import Type.Data.List (Nil')
186+
185187
...
186188
187-
client :: Client _ Query Mutation Void <- createClient
189+
client :: Client _ Nil' Query Mutation Void <- createClient
188190
{ url: "http://localhost:4000/graphql"
189191
, authToken: Nothing
190192
, headers: []
@@ -209,9 +211,11 @@ import MySchema (Query, Subscription, Mutation)
209211
import GraphQL.Client.BaseClients.Apollo (createSubscriptionClient)
210212
import GraphQL.Client.Subscription (subscription)
211213
import GraphQL.Client.Types (Client)
214+
import Type.Data.List (Nil')
215+
212216
...
213217
214-
client :: Client _ Query Mutation Subscription <-
218+
client :: Client _ Nil' Query Mutation Subscription <-
215219
createSubscriptionClient
216220
{ url: "http://localhost:4000/graphql"
217221
, authToken: Nothing
@@ -411,6 +415,13 @@ This type class specifies their graphql type.
411415

412416
There is a full example in the examples directory.
413417

418+
### Directives
419+
420+
Only top level directives, that have a query, mutation or subscription location are currently supported.
421+
422+
Please look in the example/12-directives to see an example of this.
423+
424+
414425
### Full responses
415426

416427
If 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
@@ -421,6 +432,16 @@ If you wish to get the full response, as per the [GraphQL Spec](https://spec.gra
421432

422433
These will include all errors and extensions in the response, even if a response of the correct type has been returned.
423434

435+
### Full responses as Json
436+
437+
If you wish to get the full response as json use the "Json" versions of the query functions
438+
439+
- `queryJson`
440+
- `mutationJson`
441+
- `subscriptionJson`
442+
443+
These will return the raw json returned by the server inside a newtype `GqlResJson` with phanton types for the schema, query and response. These can be useful for creating your own abstractions using that require the unchanged json response.
444+
424445
### Apollo only features
425446

426447
With apollo you can make type checked cache updates. To see examples of this look at `examples/6-watch-query` and `examples/7-watch-query-optimistic`. You can also set many options for queries, mutations and subscriptions using , `queryOpts` , `mutationOpts`, `subscriptionOpts` respectively.

Diff for: codegen/schema/get-gql-schema.mjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import fetch from 'node-fetch';
22
import {
33
getIntrospectionQuery,
4-
printSchema,
5-
buildClientSchema
64
} from 'graphql';
75

86
export async function getGqlSchema ({ moduleName, cache, url, token }) {
@@ -26,9 +24,11 @@ export async function getGqlSchema ({ moduleName, cache, url, token }) {
2624
}
2725
)
2826

29-
const { data } = await response.json()
30-
31-
const schema = printSchema(buildClientSchema(data))
27+
const { data: schema, errors } = await response.json()
28+
29+
if (errors) {
30+
throw new Error(errors)
31+
}
3232

3333
return { moduleName, cache, schema }
3434
} catch (err) {

Diff for: codegen/schema/index.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export async function generateSchemas (opts, gqlEndpoints) {
1212
await rm(opts.dir)
1313
await mkdirp(opts.dir)
1414
await mkdirp(opts.dir + '/Schema')
15+
await mkdirp(opts.dir + '/Enum')
16+
await mkdirp(opts.dir + '/Directives')
1517
const schemas = await Promise.all(gqlEndpoints.map(getGqlSchema))
1618

1719
return await writePursSchemas(opts, schemas)
@@ -22,4 +24,4 @@ export async function generateSchema (opts) {
2224
const moduleName = modulePath[modulePath.length - 1]
2325

2426
return generateSchemas({ ...opts, modulePath: modulePath.slice(0, -1) }, [{ moduleName, url }])
25-
}
27+
}

Diff for: codegen/schema/write-purs-schema.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export async function writePursSchemas (opts, gqlSchemas) {
2323
throw new Error(parseError)
2424
}
2525

26-
const { schemas, enums, symbols } = result
26+
const { schemas, enums, directives, symbols } = result
2727

28-
await Promise.all([...schemas, ...enums, symbols].map(({ path, code }) => writeFileRec(path, code)))
28+
await Promise.all([...schemas, ...enums, ...directives, symbols].map(({ path, code }) => writeFileRec(path, code)))
2929

3030
return result
3131
}

Diff for: e2e/1-affjax/package-lock.json

+43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: e2e/1-affjax/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"express": "^4.17.1",
1717
"express-graphql": "^0.12.0",
1818
"graphql": "^15.4.0",
19+
"isomorphic-ws": "^5.0.0",
1920
"xhr2": "^0.2.0"
2021
}
2122
}

Diff for: e2e/1-affjax/src/Main.purs

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import Effect (Effect)
88
import Effect.Aff (Aff, launchAff_)
99
import Effect.Class.Console (logShow)
1010
import GraphQL.Client.Args ((=>>))
11+
import GraphQL.Client.Operation (OpQuery)
1112
import GraphQL.Client.BaseClients.Affjax.Node (AffjaxNodeClient(..))
1213
import GraphQL.Client.Query (query, queryFullRes)
1314
import GraphQL.Client.Types (class GqlQuery, Client(..))
15+
import Type.Data.List (Nil')
1416
import Type.Proxy (Proxy(..))
1517

1618
main :: Effect Unit
@@ -31,13 +33,13 @@ main =
3133
-- Run gql query
3234
queryGql ::
3335
forall query returns.
34-
GqlQuery Schema query returns =>
36+
GqlQuery Nil' OpQuery Schema query returns =>
3537
DecodeJson returns =>
3638
String -> query -> Aff returns
37-
queryGql = query client
39+
queryGql = query client
3840

39-
client :: Client AffjaxNodeClient Schema Void Void
40-
client = (Client $ AffjaxNodeClient "http://localhost:4000/graphql" [])
41+
client :: Client AffjaxNodeClient Nil' Schema Void Void
42+
client = (Client $ AffjaxNodeClient "http://localhost:4000/graphql" [])
4143

4244
-- Schema
4345
type Schema
@@ -50,9 +52,9 @@ type Widget
5052
, id :: Int
5153
}
5254

53-
-- Symbols
55+
-- Symbols
5456
prop :: Proxy "prop"
5557
prop = Proxy
5658

5759
name :: Proxy "name"
58-
name = Proxy
60+
name = Proxy
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: e2e/3-comments/package-lock.json renamed to e2e/2-comments/package-lock.json

+43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: e2e/3-comments/package.json renamed to e2e/2-comments/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"express": "4.17.1",
1919
"express-graphql": "0.12.0",
2020
"graphql": "15.4.0",
21+
"isomorphic-ws": "^5.0.0",
2122
"mkdirp": "1.0.4",
2223
"rimraf": "3.0.2",
2324
"xhr2": "0.2.0"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: e2e/3-comments/src/Main.purs renamed to e2e/2-comments/src/Main.purs

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import Generated.Gql.Schema.Admin (Query)
1111
import Generated.Gql.Schema.Admin.Enum.Colour (Colour(..))
1212
import Generated.Gql.Symbols (colour)
1313
import GraphQL.Client.Args ((=>>))
14+
import GraphQL.Client.Operation (OpQuery)
1415
import GraphQL.Client.Query (query_)
1516
import GraphQL.Client.Types (class GqlQuery)
17+
import Type.Data.List (Nil')
1618
import GraphQL.Client.Union (GqlUnion(..))
1719
import Type.Proxy (Proxy(..))
1820

@@ -22,14 +24,14 @@ main =
2224
{ widgets } <-
2325
queryGql "WidgetColoursWithId1"
2426
{ widgets: { colour: RED } =>> { colour } }
25-
27+
2628
-- Will log [ RED ] as there is one red widget
2729
logShow $ map _.colour widgets
2830

2931
-- Run gql query
3032
queryGql ::
3133
forall query returns.
32-
GqlQuery Query query returns =>
34+
GqlQuery Nil' OpQuery Query query returns =>
3335
DecodeJson returns =>
3436
String -> query -> Aff returns
3537
queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Query)
File renamed without changes.

Diff for: e2e/2-purty/README.md

-4
This file was deleted.

Diff for: e2e/2-purty/package.json

-28
This file was deleted.

0 commit comments

Comments
 (0)