Skip to content

Commit

Permalink
feat: add example app for sendGraphQLRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheyenbrock committed Jan 29, 2022
1 parent ae79ea1 commit 76bb3bd
Show file tree
Hide file tree
Showing 16 changed files with 28,843 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/github-explorer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GITHUB_TOKEN='ghp_ABC...'
6 changes: 6 additions & 0 deletions examples/github-explorer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules

/.cache
/build
/public/build
.env
10 changes: 10 additions & 0 deletions examples/github-explorer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# github-explorer

This exmple shows how to use `remix-graphql` to execute GraphQL operations
against a remote GraphQL API in your loaders and actions. It uses the
`sendGraphQLRequest` function.

In the example app you can search GitHub users by name and look up their ten
most starred public repositories. The search query runs in an action function
that handles a form submission with the string to search by. The query for
a user and the repos runs in a loader function.
4 changes: 4 additions & 0 deletions examples/github-explorer/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { hydrate } from "react-dom";
import { RemixBrowser } from "remix";

hydrate(<RemixBrowser />, document);
21 changes: 21 additions & 0 deletions examples/github-explorer/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { renderToString } from "react-dom/server";
import { RemixServer } from "remix";
import type { EntryContext } from "remix";

export default function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext
) {
const markup = renderToString(
<RemixServer context={remixContext} url={request.url} />
);

responseHeaders.set("Content-Type", "text/html");

return new Response("<!DOCTYPE html>" + markup, {
status: responseStatusCode,
headers: responseHeaders
});
}
1 change: 1 addition & 0 deletions examples/github-explorer/app/graphql/endpoint.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const endpoint = "https://api.github.com/graphql";
1 change: 1 addition & 0 deletions examples/github-explorer/app/graphql/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ArrayItem<T> = T extends Array<infer S> ? S : never;
Loading

0 comments on commit 76bb3bd

Please sign in to comment.