Skip to content

Commit 37ad500

Browse files
authored
Merge pull request #608 from supabase/or/docker-graphiql
Fix dockerfile + graphiql
2 parents d99d691 + e7338d6 commit 37ad500

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ services:
66
build:
77
context: .
88
dockerfile: ./dockerfiles/db/Dockerfile
9+
args:
10+
PG_VERSION: 17
911
volumes:
1012
- ./dockerfiles/db/setup.sql:/docker-entrypoint-initdb.d/setup.sql
1113
ports:

dockerfiles/db/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG PG_VERSION=15
1+
ARG PG_VERSION=17
22
FROM postgres:${PG_VERSION}
33
RUN apt-get update
44

@@ -35,6 +35,6 @@ RUN cargo pgrx init --pg${PG_MAJOR} $(which pg_config)
3535
USER root
3636

3737
COPY . .
38-
RUN cargo pgrx install
38+
RUN cargo pgrx install --release --features pg${PG_MAJOR}
3939

4040
USER postgres

dockerfiles/graphiql/index.html

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
<html lang="en">
33
<head>
44
<title>GraphiQL - pg_graphql</title>
5-
6-
<link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" />
5+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/graphiql.min.css" />
76
</head>
87

98
<body style="margin: 0">
@@ -18,16 +17,57 @@
1817
></script>
1918
<script
2019
crossorigin
21-
src="https://unpkg.com/graphiql/graphiql.min.js"
20+
src="https://unpkg.com/graphiql@3.0.6/graphiql.min.js"
2221
></script>
2322
<script>
24-
const fetcher = GraphiQL.createFetcher({
25-
url: "http://localhost:3001/rpc/graphql",
26-
});
27-
ReactDOM.render(
28-
React.createElement(GraphiQL, { fetcher: fetcher }),
29-
document.getElementById("graphiql")
30-
);
23+
// Custom fetcher for PostgREST GraphQL function
24+
const fetcher = async (graphQLParams) => {
25+
const response = await fetch("http://localhost:3001/rpc/graphql", {
26+
method: 'POST',
27+
headers: {
28+
'Accept': 'application/vnd.pgrst.object+json;nulls=stripped',
29+
'Content-Type': 'application/json'
30+
},
31+
body: JSON.stringify({
32+
query: graphQLParams.query,
33+
variables: graphQLParams.variables || {},
34+
operationName: graphQLParams.operationName || null,
35+
extensions: null
36+
})
37+
});
38+
39+
return response.json();
40+
};
41+
42+
const defaultQuery = `# Welcome to pg_graphql!
43+
# Try this query:
44+
45+
query {
46+
accountCollection {
47+
edges {
48+
node {
49+
id
50+
email
51+
createdAt
52+
blogCollection {
53+
edges {
54+
node {
55+
id
56+
name
57+
description
58+
}
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}`;
65+
66+
const root = ReactDOM.createRoot(document.getElementById("graphiql"));
67+
root.render(React.createElement(GraphiQL, {
68+
fetcher: fetcher,
69+
query: defaultQuery
70+
}));
3171
</script>
3272
</body>
3373
</html>

0 commit comments

Comments
 (0)