Skip to content

Commit c2fb94e

Browse files
committed
feat: modify Client API to place variables in last positional argument. (#226)
1 parent c4740ac commit c2fb94e

File tree

24 files changed

+360
-365
lines changed

24 files changed

+360
-365
lines changed

README.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg)](#contributors)
55
[![Build Status](https://travis-ci.com/FormidableLabs/reason-urql.svg?branch=master)](https://travis-ci.com/FormidableLabs/reason-urql)
66
[![Maintenance Status][maintenance-image]](#maintenance-status)
7-
[![Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://spectrum.chat/urql)
87

98
Reason bindings for Formidable's Universal React Query Library, [`urql`](https://github.com/FormidableLabs/urql).
109

@@ -21,40 +20,50 @@ Reason bindings for Formidable's Universal React Query Library, [`urql`](https:/
2120
## 📋 Documentation
2221

2322
- [Getting Started](/docs/getting-started.md)
24-
- [API](/docs)
23+
- [Client and Provider](/docs/client-and-provider.md)
24+
- [Hooks](/docs/hooks.md)
25+
- [Exchanges](/docs/exchanges.md)
26+
- [Errors](/docs/error.md)
27+
- [Advanced](/docs/advanced.md)
2528

2629
## 💾 Installation
2730

28-
#### 1. Install `reason-urql`.
31+
#### 1. Install `reason-urql` and its `peerDependencies`.
2932

3033
```sh
31-
yarn add reason-urql
34+
yarn add reason-urql urql graphql
3235
```
3336

34-
#### 2. Add `graphql_ppx_re`.
37+
We try to keep our bindings as close to latest `urql` as possible. However, `urql` tends to make releases a bit ahead of `reason-urql`. To get a compatible version, we recommend always staying strictly within this project's `peerDependency` range for `urql`.
3538

36-
To get the most out of compile time type checks for your GraphQL queries, mutations, and subscriptions, we recommend using [`graphql_ppx_re`](https://github.com/reasonml-community/graphql_ppx). `useDynamicMutation` in particular takes advantage of some of its internals for an excellent experience writing type safe code to access your GraphQL responses.
39+
#### 2. Add `@reasonml-community/graphql-ppx`.
40+
41+
To get the most out of compile time type checks for your GraphQL queries, mutations, and subscriptions, we use [`@reasonml-community/graphql-ppx`](https://github.com/reasonml-community/graphql-ppx). Add this to your project's `devDependencies`.
3742

3843
```sh
39-
yarn add @baransu/graphql_ppx_re --dev
44+
yarn add @reasonml-community/graphql-ppx --dev
4045
```
4146

4247
#### 3. Update `bsconfig.json`.
4348

44-
Add `reason-urql` to your `bs-dependencies` and `graphql_ppx_re` to your `ppx_flags` in `bsconfig.json`.
49+
Add `reason-urql`, `wonka`, and `@reasonml-community/graphql-ppx` to your `bs-dependencies` and `@reasonml-community/graphql-ppx/ppx` to your `ppx_flags` in `bsconfig.json`.
4550

4651
```json
4752
{
48-
"bs-dependencies": ["reason-urql"],
49-
"ppx-flags": ["@baransu/graphql_ppx_re/ppx"]
53+
"bs-dependencies": [
54+
"reason-urql",
55+
"wonka",
56+
"@reasonml-community/graphql-ppx"
57+
],
58+
"ppx-flags": ["@reasonml-community/graphql-ppx/ppx"]
5059
}
5160
```
5261

5362
#### 4. Send an introspection query to your API.
5463

55-
Finally, you'll need to send an introspection query to your GraphQl API, using a tool like [`graphql-cli`](https://github.com/Urigo/graphql-cli/). You should generate a file called `graphql_schema.json` at the root of your project that `graphql_ppx_re` can use to type check your queries. **You should check this file into version control** and keep it updated as your API changes.
64+
Finally, you'll need to send an introspection query to your GraphQl API, using a tool like [`graphql-cli`](https://github.com/Urigo/graphql-cli/). You should generate a file called `graphql_schema.json` at the root of your project that `graphql-ppx` can use to type check your queries. **You should check this file into version control** and keep it updated as your API changes.
5665

57-
For additional instructions, head [here](https://github.com/reasonml-community/graphql_ppx#usage).
66+
For additional help, head [here](https://github.com/reasonml-community/graphql-ppx#schema).
5867

5968
```sh
6069
npx get-graphql-schema ENDPOINT_URL -j > graphql_schema.json
@@ -146,6 +155,7 @@ This project follows the [all contributors spec](https://github.com/kentcdodds/a
146155

147156
<!-- markdownlint-enable -->
148157
<!-- prettier-ignore-end -->
158+
149159
<!-- ALL-CONTRIBUTORS-LIST:END -->
150160

151161
## Maintenance Status

__tests__/Types_test.re

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ let mockOperation =
1919
key: 1,
2020
query: "query {\ndogs {\nname\nlikes\n}\n}",
2121
variables: None,
22-
operationName: `Query,
22+
kind: `Query,
2323
context: mockOperationContext,
2424
};
2525

2626
describe("Types", () => {
27-
describe("urqlResponseToReason", () => {
27+
describe("hookResponseToReason", () => {
2828
it(
2929
"should correctly return Fetching constructor if fetching is true and no data has been received",
3030
() => {
3131
let response =
32-
Types.{
32+
Types.Hooks.{
3333
operation: mockOperation,
3434
fetching: true,
3535
data: Js.Nullable.undefined,
@@ -38,17 +38,17 @@ describe("Types", () => {
3838
stale: false,
3939
};
4040
let parse = _json => ();
41-
let result = Types.urqlResponseToReason(~response, ~parse);
41+
let result = Types.Hooks.hookResponseToReason(~response, ~parse);
4242

43-
Expect.(expect(result.response) |> toEqual(Types.Fetching));
43+
Expect.(expect(result.response) |> toEqual(Types.Hooks.Fetching));
4444
},
4545
);
4646

4747
it(
4848
"should return Data constructor if the GraphQL API responded with data",
4949
() => {
5050
let response =
51-
Types.{
51+
Types.Hooks.{
5252
operation: mockOperation,
5353
fetching: false,
5454
data: Js.Nullable.return(Js.Json.string("Hello")),
@@ -57,10 +57,10 @@ describe("Types", () => {
5757
stale: false,
5858
};
5959
let parse = json => Js.Json.decodeString(json);
60-
let result = Types.urqlResponseToReason(~response, ~parse);
60+
let result = Types.Hooks.hookResponseToReason(~response, ~parse);
6161

6262
Expect.(
63-
expect(result.response) |> toEqual(Types.Data(Some("Hello")))
63+
expect(result.response) |> toEqual(Types.Hooks.Data(Some("Hello")))
6464
);
6565
});
6666

@@ -95,7 +95,7 @@ describe("Types", () => {
9595
};
9696

9797
let response =
98-
Types.{
98+
Types.Hooks.{
9999
operation: mockOperation,
100100
fetching: false,
101101
data: Js.Nullable.return(Js.Json.string("Hello")),
@@ -105,11 +105,13 @@ describe("Types", () => {
105105
};
106106

107107
let parse = json => Js.Json.decodeString(json);
108-
let result = Types.urqlResponseToReason(~response, ~parse);
108+
let result = Types.Hooks.hookResponseToReason(~response, ~parse);
109109

110110
Expect.(
111111
expect(result.response)
112-
|> toEqual(Types.PartialData(Some("Hello"), error.graphQLErrors))
112+
|> toEqual(
113+
Types.Hooks.PartialData(Some("Hello"), error.graphQLErrors),
114+
)
113115
);
114116
},
115117
);
@@ -145,7 +147,7 @@ describe("Types", () => {
145147
};
146148

147149
let response =
148-
Types.{
150+
Types.Hooks.{
149151
operation: mockOperation,
150152
fetching: false,
151153
data: Js.Nullable.undefined,
@@ -154,14 +156,14 @@ describe("Types", () => {
154156
stale: false,
155157
};
156158
let parse = _json => ();
157-
let result = Types.urqlResponseToReason(~response, ~parse);
159+
let result = Types.Hooks.hookResponseToReason(~response, ~parse);
158160

159-
Expect.(expect(result.response) |> toEqual(Types.Error(error)));
161+
Expect.(expect(result.response) |> toEqual(Types.Hooks.Error(error)));
160162
});
161163

162164
it("should return Empty constructor if none of the above apply", () => {
163165
let response =
164-
Types.{
166+
Types.Hooks.{
165167
operation: mockOperation,
166168
fetching: false,
167169
data: Js.Nullable.undefined,
@@ -170,9 +172,9 @@ describe("Types", () => {
170172
stale: false,
171173
};
172174
let parse = _json => ();
173-
let result = Types.urqlResponseToReason(~response, ~parse);
175+
let result = Types.Hooks.hookResponseToReason(~response, ~parse);
174176

175-
Expect.(expect(result.response) |> toEqual(Types.Empty));
177+
Expect.(expect(result.response) |> toEqual(Types.Hooks.Empty));
176178
});
177179
})
178180
});

0 commit comments

Comments
 (0)