Skip to content

Commit

Permalink
Use BuckleScript's native namespacing feature. (teamwalnut#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
parkerziegler authored and tatchi committed Aug 25, 2020
1 parent 0a2dd7f commit dab723a
Show file tree
Hide file tree
Showing 39 changed files with 268 additions and 314 deletions.
41 changes: 22 additions & 19 deletions __tests__/UrqlClient_test.re → __tests__/Client_test.re
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
open Jest;
open ReasonUrql;

let it = test;

describe("UrqlClient", () => {
describe("Client", () => {
describe("Client with only a url provided", () => {
let client = Client.make(~url="https://localhost:3000", ());

Expand Down Expand Up @@ -86,7 +85,7 @@ describe("UrqlClient", () => {
let client =
Client.make(
~url="https://localhost:3000",
~exchanges=[|Exchanges.debugExchange|],
~exchanges=[|Client.Exchanges.debugExchange|],
(),
);

Expand All @@ -97,11 +96,11 @@ describe("UrqlClient", () => {
Expect.(
expect(() =>
[|
Exchanges.debugExchange,
Exchanges.cacheExchange,
Exchanges.fetchExchange,
Client.Exchanges.debugExchange,
Client.Exchanges.cacheExchange,
Client.Exchanges.fetchExchange,
|]
|> Exchanges.composeExchanges
|> Client.Exchanges.composeExchanges
)
|> not
|> toThrow
Expand All @@ -112,11 +111,11 @@ describe("UrqlClient", () => {
Expect.(
expect([|
[|
Exchanges.debugExchange,
Exchanges.cacheExchange,
Exchanges.fetchExchange,
Client.Exchanges.debugExchange,
Client.Exchanges.cacheExchange,
Client.Exchanges.fetchExchange,
|]
|> Exchanges.composeExchanges,
|> Client.Exchanges.composeExchanges,
|])
|> toHaveLength(1)
)
Expand All @@ -125,7 +124,7 @@ describe("UrqlClient", () => {

describe("ssrExchange", () => {
it("should exist and be callable", () =>
Expect.(expect(Exchanges.ssrExchange()) |> toMatchSnapshot)
Expect.(expect(Client.Exchanges.ssrExchange()) |> toMatchSnapshot)
);

it(
Expand All @@ -135,16 +134,20 @@ describe("UrqlClient", () => {
Js.Dict.set(json, "key", Js.Json.number(1.));
Js.Dict.set(json, "key2", Js.Json.number(2.));
let data = Js.Json.object_(json);
let serializedResult = Exchanges.{data: Some(data), error: None};
let serializedResult =
Client.Exchanges.{data: Some(data), error: None};

let initialState = Js.Dict.empty();
Js.Dict.set(initialState, "query", serializedResult);
let ssrExchangeParams =
Exchanges.{initialState: Some(initialState), isClient: Some(false)};
Client.Exchanges.{
initialState: Some(initialState),
isClient: Some(false),
};

Expect.(
expect(() =>
Exchanges.ssrExchange(~ssrExchangeParams, ())
Client.Exchanges.ssrExchange(~ssrExchangeParams, ())
)
|> not
|> toThrow
Expand All @@ -154,11 +157,11 @@ describe("UrqlClient", () => {
it(
"should expose an extractData method for extracting server-side rendered data",
() => {
let ssrCache = Exchanges.ssrExchange();
let ssrCache = Client.Exchanges.ssrExchange();

Expect.(
expect(() =>
Exchanges.extractData(~exchange=ssrCache)
Client.Exchanges.extractData(~exchange=ssrCache)
)
|> not
|> toThrow
Expand All @@ -172,11 +175,11 @@ describe("UrqlClient", () => {
Js.Dict.set(json, "key", Js.Json.number(1.));
Js.Dict.set(json, "key2", Js.Json.number(2.));
let data = Js.Json.object_(json);
let ssrCache = Exchanges.ssrExchange();
let ssrCache = Client.Exchanges.ssrExchange();

Expect.(
expect(() =>
Exchanges.restoreData(~exchange=ssrCache, ~restore=data)
Client.Exchanges.restoreData(~exchange=ssrCache, ~restore=data)
)
|> not
|> toThrow
Expand Down
38 changes: 14 additions & 24 deletions __tests__/UrqlTypes_test.re → __tests__/Types_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,35 @@ open Jest;

let it = test;

describe("UrqlTypes", () => {
describe("Types", () => {
describe("urqlResponseToReason", () => {
it(
"should correctly return Fetching constructor if fetching is true and no data has been received",
() => {
let response =
UrqlTypes.{
fetching: true,
data: None,
error: None,
extensions: None,
};
Types.{fetching: true, data: None, error: None, extensions: None};
let parse = _json => ();
let result = UrqlTypes.urqlResponseToReason(~response, ~parse);
let result = Types.urqlResponseToReason(~response, ~parse);

Expect.(expect(result.response) |> toEqual(UrqlTypes.Fetching));
Expect.(expect(result.response) |> toEqual(Types.Fetching));
},
);

it(
"should return Data constructor if the GraphQL API responded with data",
() => {
let response =
UrqlTypes.{
Types.{
fetching: false,
data: Some(Js.Json.string("Hello")),
error: None,
extensions: None,
};
let parse = json => Js.Json.decodeString(json);
let result = UrqlTypes.urqlResponseToReason(~response, ~parse);
let result = Types.urqlResponseToReason(~response, ~parse);

Expect.(
expect(result.response) |> toEqual(UrqlTypes.Data(Some("Hello")))
expect(result.response) |> toEqual(Types.Data(Some("Hello")))
);
});

Expand All @@ -50,38 +45,33 @@ describe("UrqlTypes", () => {
};

let error =
UrqlCombinedError.{
CombinedError.{
message: "Error returned by GraphQL API",
graphQLErrors: None,
networkError: None,
response: None,
};

let response =
UrqlTypes.{
Types.{
fetching: false,
data: None,
error: Some(errorJs),
extensions: None,
};
let parse = _json => ();
let result = UrqlTypes.urqlResponseToReason(~response, ~parse);
let result = Types.urqlResponseToReason(~response, ~parse);

Expect.(expect(result.response) |> toEqual(UrqlTypes.Error(error)));
Expect.(expect(result.response) |> toEqual(Types.Error(error)));
});

it("should return NotFound constructor if none of the above apply", () => {
let response =
UrqlTypes.{
fetching: false,
data: None,
error: None,
extensions: None,
};
Types.{fetching: false, data: None, error: None, extensions: None};
let parse = _json => ();
let result = UrqlTypes.urqlResponseToReason(~response, ~parse);
let result = Types.urqlResponseToReason(~response, ~parse);

Expect.(expect(result.response) |> toEqual(UrqlTypes.NotFound));
Expect.(expect(result.response) |> toEqual(Types.NotFound));
});
})
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`UrqlClient Client with default requestPolicy should accept a default requestPolicy 1`] = `
exports[`Client Client with default requestPolicy should accept a default requestPolicy 1`] = `
Client {
"activeOperations": Object {},
"createOperationContext": [Function],
Expand All @@ -21,7 +21,7 @@ Client {
}
`;

exports[`UrqlClient Client with exchanges provided should instantiate a client with exchanges 1`] = `
exports[`Client Client with exchanges provided should instantiate a client with exchanges 1`] = `
Client {
"activeOperations": Object {},
"createOperationContext": [Function],
Expand All @@ -42,7 +42,7 @@ Client {
}
`;

exports[`UrqlClient Client with fetchOptions provided should instantiate a client instance with fetchOptions provided as FetchFn 1`] = `
exports[`Client Client with fetchOptions provided should instantiate a client instance with fetchOptions provided as FetchFn 1`] = `
Client {
"activeOperations": Object {},
"createOperationContext": [Function],
Expand All @@ -63,7 +63,7 @@ Client {
}
`;

exports[`UrqlClient Client with fetchOptions provided should instantiate a client instance with fetchOptions provided as FetchOpts 1`] = `
exports[`Client Client with fetchOptions provided should instantiate a client instance with fetchOptions provided as FetchOpts 1`] = `
Client {
"activeOperations": Object {},
"createOperationContext": [Function],
Expand Down Expand Up @@ -91,7 +91,7 @@ Client {
}
`;

exports[`UrqlClient Client with only a url provided should instantiate a client instance 1`] = `
exports[`Client Client with only a url provided should instantiate a client instance 1`] = `
Client {
"activeOperations": Object {},
"createOperationContext": [Function],
Expand All @@ -112,7 +112,7 @@ Client {
}
`;

exports[`UrqlClient Client with suspense flag should accept a suspense flag to enable experimental SSR mode 1`] = `
exports[`Client Client with suspense flag should accept a suspense flag to enable experimental SSR mode 1`] = `
Client {
"activeOperations": Object {},
"createOperationContext": [Function],
Expand All @@ -133,9 +133,9 @@ Client {
}
`;

exports[`UrqlClient ssrExchange should exist and be callable 1`] = `[Function]`;
exports[`Client ssrExchange should exist and be callable 1`] = `[Function]`;

exports[`UrqlClient with custom fetch implementation should accept a custom fetch implementation 1`] = `
exports[`Client with custom fetch implementation should accept a custom fetch implementation 1`] = `
Client {
"activeOperations": Object {},
"createOperationContext": [Function],
Expand All @@ -156,7 +156,7 @@ Client {
}
`;

exports[`UrqlClient with custom fetch implementation should work with a fetcher using Fetch.request 1`] = `
exports[`Client with custom fetch implementation should work with a fetcher using Fetch.request 1`] = `
Client {
"activeOperations": Object {},
"createOperationContext": [Function],
Expand Down
2 changes: 1 addition & 1 deletion bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "reason-urql",
"namespace": true,
"reason": {
"react-jsx": 3
},
Expand All @@ -22,7 +23,6 @@
}
],
"suffix": ".bs.js",
"namespace": false,
"bs-dependencies": ["reason-react", "wonka", "bs-fetch"],
"bs-dev-dependencies": ["@glennsl/bs-jest"],
"refmt": 3,
Expand Down
20 changes: 8 additions & 12 deletions examples/1-execute-query-mutation/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3332,7 +3332,7 @@ react-is@^16.8.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==

react-wonka@^1.0.2:
react-wonka@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/react-wonka/-/react-wonka-1.0.3.tgz#2d997403be347489e1161cb58d502ac683499847"
integrity sha512-7ocCcMnSxc7zD06V6H2Er4PJNbHQL2bityy6aZPrsn2JqJSP4SEkCzdvCk+nQVKDDqO8Lk5L5F9GG7PUB8gGsA==
Expand Down Expand Up @@ -3393,12 +3393,8 @@ reason-react@^0.7.0:
react-dom ">=16.8.1"

"reason-urql@link:../..":
version "1.7.0"
dependencies:
bs-fetch "^0.5.2"
graphql "^14.1.1"
urql "1.5.1"
wonka "^3.2.2"
version "0.0.0"
uid ""

regenerator-runtime@^0.13.4:
version "0.13.5"
Expand Down Expand Up @@ -4146,12 +4142,12 @@ url@^0.11.0:
punycode "1.3.2"
querystring "0.2.0"

[email protected].1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/urql/-/urql-1.6.1.tgz#ac40eddcdfb4b7cd3308b2c2a6e0fa426a3904c6"
integrity sha512-SqMBJiImlMppg7fodlIOAd1/7C1D7VxJ1ZNuk1p5nlmqbFAy7tjQlEbqtxEwNg+Rua3Pz/FPKR8m+LuMrnvWXA==
[email protected].3:
version "1.6.3"
resolved "https://registry.yarnpkg.com/urql/-/urql-1.6.3.tgz#0484a90a01d6fc8d0a6fb96bb4b2b2146a612c0d"
integrity sha512-KX8qHTGo8deSg41rrQEk9JhJTz6w/LBCdWhYutYjbCUrkoAF4lEiCkgOEiO0fEf+hpDg0nQTTkHTpRbgQ0yh1g==
dependencies:
react-wonka "^1.0.2"
react-wonka "^1.0.3"
wonka "^3.2.1"

use@^3.1.0:
Expand Down
2 changes: 1 addition & 1 deletion examples/2-query/src/index.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ open ReasonUrql;
let client = Client.make(~url="https://graphql-pokemon.now.sh", ());

ReactDOMRe.renderToElementWithId(
<Provider value=client> <Container /> </Provider>,
<Context.Provider value=client> <Container /> </Context.Provider>,
"root",
);
20 changes: 8 additions & 12 deletions examples/2-query/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3330,7 +3330,7 @@ react-is@^16.8.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==

react-wonka@^1.0.2:
react-wonka@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/react-wonka/-/react-wonka-1.0.3.tgz#2d997403be347489e1161cb58d502ac683499847"
integrity sha512-7ocCcMnSxc7zD06V6H2Er4PJNbHQL2bityy6aZPrsn2JqJSP4SEkCzdvCk+nQVKDDqO8Lk5L5F9GG7PUB8gGsA==
Expand Down Expand Up @@ -3392,12 +3392,8 @@ reason-react@^0.7.0:
react-dom ">=16.8.1"

"reason-urql@link:../..":
version "1.7.0"
dependencies:
bs-fetch "^0.5.2"
graphql "^14.1.1"
urql "1.5.1"
wonka "^3.2.2"
version "0.0.0"
uid ""

regenerator-runtime@^0.13.2:
version "0.13.2"
Expand Down Expand Up @@ -4145,12 +4141,12 @@ url@^0.11.0:
punycode "1.3.2"
querystring "0.2.0"

[email protected].1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/urql/-/urql-1.6.1.tgz#ac40eddcdfb4b7cd3308b2c2a6e0fa426a3904c6"
integrity sha512-SqMBJiImlMppg7fodlIOAd1/7C1D7VxJ1ZNuk1p5nlmqbFAy7tjQlEbqtxEwNg+Rua3Pz/FPKR8m+LuMrnvWXA==
[email protected].3:
version "1.6.3"
resolved "https://registry.yarnpkg.com/urql/-/urql-1.6.3.tgz#0484a90a01d6fc8d0a6fb96bb4b2b2146a612c0d"
integrity sha512-KX8qHTGo8deSg41rrQEk9JhJTz6w/LBCdWhYutYjbCUrkoAF4lEiCkgOEiO0fEf+hpDg0nQTTkHTpRbgQ0yh1g==
dependencies:
react-wonka "^1.0.2"
react-wonka "^1.0.3"
wonka "^3.2.1"

use@^3.1.0:
Expand Down
2 changes: 1 addition & 1 deletion examples/3-mutation/src/index.re
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ open ReasonUrql;
let client = Client.make(~url="https://formidadog-ql.now.sh", ());

ReactDOMRe.renderToElementWithId(
<Provider value=client> <Grid client /> </Provider>,
<Context.Provider value=client> <Grid client /> </Context.Provider>,
"root",
);
Loading

0 comments on commit dab723a

Please sign in to comment.