Skip to content
This repository was archived by the owner on Dec 4, 2024. It is now read-only.

Commit 534121c

Browse files
committed
feat: move from apollo to nhost.graphql.request
since we don't import react here apollo breaks some of parcels code optimization
1 parent 42dc9f5 commit 534121c

File tree

6 files changed

+39
-62
lines changed

6 files changed

+39
-62
lines changed

packages/app/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"dev": "parcel watch"
1313
},
1414
"dependencies": {
15-
"@apollo/client": "^3.6.9",
1615
"@firebase-proxy/core": "file:../core",
1716
"@nhost/nhost-js": "^1.4.11"
1817
},

packages/app/src/index.js

-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { NhostClient } from "@nhost/nhost-js";
2-
import { ApolloClient, InMemoryCache } from "@apollo/client/core";
3-
42
import { Logger } from "@firebase-proxy/core";
53

64
export const logger = new Logger("firestore");
@@ -13,21 +11,6 @@ export function initializeApp(configuration) {
1311
subdomain: process.env.REACT_APP_NHOST_SUBDOMAIN || "localhost",
1412
region: process.env.REACT_APP_NHOST_REGION || null
1513
});
16-
17-
window.apollo = new ApolloClient({
18-
uri: window.nhost.graphql.getUrl(),
19-
cache: new InMemoryCache(),
20-
defaultOptions: {
21-
watchQuery: {
22-
fetchPolicy: "no-cache",
23-
errorPolicy: "ignore"
24-
},
25-
query: {
26-
fetchPolicy: "no-cache",
27-
errorPolicy: "all"
28-
}
29-
}
30-
});
3114
}
3215

3316
return window.nhost;

packages/auth/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"dev": "parcel watch"
1313
},
1414
"dependencies": {
15-
"@apollo/client": "^3.6.9",
1615
"@firebase-proxy/core": "file:../core",
17-
"@nhost/nhost-js": "^1.4.11"
16+
"@nhost/nhost-js": "^1.4.11",
17+
"graphql-tag": "^2.12.6"
1818
},
1919
"devDependencies": {
2020
"parcel": "^2.7.0"

packages/auth/src/index.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { gql } from "@apollo/client";
1+
import { gql } from "graphql-tag";
22
import { Logger } from "@firebase-proxy/core";
33

44
export const logger = new Logger("auth");
@@ -62,25 +62,21 @@ export function onAuthStateChanged(auth, callback) {
6262
export async function fetchSignInMethodsForEmail(auth, email) {
6363
logger.log("fetchSignInMethodsForEmail", { auth, email });
6464

65-
if (!window.apollo) {
66-
logger.log("apollo has not started");
65+
if (!window.nhost) {
66+
logger.log("nhost has not started");
6767

6868
return [];
6969
}
7070

71-
const result = await window.apollo.query({
72-
query: gql`
71+
const result = await window.graphql.request.query(gql`
7372
query CheckEmail($email: citext) {
7473
users(where: {email: {_eq: $email}}) {
7574
emailVerified
7675
}
77-
}`,
78-
variables: {
79-
email
8076
}
81-
});
77+
`, { email });
8278

83-
if (!result || !result.data || !result.data.users[0] ) {
79+
if (result.error || !result.data || !result.data.users[0]) {
8480
logger.log("user does not exist", { email });
8581

8682
return [];

packages/firestore/package.json

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
{
22
"name": "@firebase-proxy/firestore",
33
"version": "0.0.1",
4-
"main": "src/index.js",
4+
"source": "src/index.js",
5+
"main": "dist/index.js",
56
"author": "",
6-
"files": ["dist"],
7+
"files": [
8+
"dist"
9+
],
710
"scripts": {
8-
"build": "npm install --save-dev && rollup -c",
9-
"dev": "npm install --save-dev && rollup -c -w"
11+
"build": "parcel build",
12+
"dev": "parcel watch"
1013
},
1114
"dependencies": {
12-
"@apollo/client": "^3.6.9",
13-
"@firebase-proxy/core": "file:../core"
15+
"@firebase-proxy/core": "file:../core",
16+
"graphql-tag": "^2.12.6"
1417
},
1518
"devDependencies": {
16-
"rollup": "2.72.1"
19+
"parcel": "^2.7.0"
1720
}
1821
}

packages/firestore/src/index.js

+21-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { gql } from "@apollo/client";
1+
import { gql } from "graphql-tag";
22
import { Logger } from "@firebase-proxy/core";
33

44
export const logger = new Logger("firestore");
@@ -49,6 +49,12 @@ export function query() {
4949
export async function setDoc(query, value) {
5050
logger.log("setting document", { query, value });
5151

52+
if (!window.nhost) {
53+
logger.log("nhost has not started");
54+
55+
return null;
56+
}
57+
5258
const mapping = schema.mapping[query.content.table];
5359

5460
if (!mapping) {
@@ -73,18 +79,13 @@ export async function setDoc(query, value) {
7379

7480
logger.log("mapped values", { mapped });
7581

76-
const result = await window.apollo.mutate({
77-
mutation: gql`
78-
mutation SetDoc($value: ${mapping.name}_insert_input!) {
79-
insert_${mapping.name}_one(object: $value) {
80-
ID
81-
}
82-
}
83-
`,
84-
variables: {
85-
value: mapped
86-
}
87-
});
82+
const result = await window.nhost.graphql.request(gql`
83+
mutation SetDoc($value: ${mapping.name}_insert_input!) {
84+
insert_${mapping.name}_one(object: $value) {
85+
ID
86+
}
87+
}
88+
`, { value: mapped });
8889

8990
logger.log("result", { result });
9091
}
@@ -113,8 +114,8 @@ class Document {
113114
}
114115

115116
async function getDocuments(query) {
116-
if (!window.apollo) {
117-
logger.log("apollo has not started");
117+
if (!window.nhost) {
118+
logger.log("nhost has not started");
118119

119120
return null;
120121
}
@@ -202,18 +203,13 @@ async function getDocuments(query) {
202203

203204
logger.log("got where statement", { where, query });
204205

205-
const result = await window.apollo.query({
206-
query: gql`
207-
query GetDoc($where: ${mapping.name}_bool_exp) {
208-
${mapping.name}(where: $where) {
209-
${Object.values(mapping.fields).join("\n")}
210-
}
206+
const result = await window.nhost.graphql.request(gql`
207+
query GetDoc($where: ${mapping.name}_bool_exp) {
208+
${mapping.name}(where: $where) {
209+
${Object.values(mapping.fields).join("\n")}
211210
}
212-
`,
213-
variables: {
214-
where: where
215211
}
216-
});
212+
`, { where });
217213

218214
logger.log("got result", { result, query });
219215

0 commit comments

Comments
 (0)