This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
create separate package for @graphql-helix/core #140
Open
mosch
wants to merge
10
commits into
contra:main
Choose a base branch
from
launchport:separate-packge
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0182fb5
create seperate package for core
mosch 63cef2b
ignore 'no-template-curly-in-string'
dan-lee c49879e
update tests
dan-lee b7520fa
Merge remote-tracking branch 'origin/master' into separate-packge
dan-lee fea945e
Merge remote-tracking branch 'origin/master' into separate-packge
dan-lee bfb776c
Update package.json
mosch fb18f32
Merge branch 'master' into separate-packge
mosch 0170b3a
mess with versions
mosch 18c8955
Merge remote-tracking branch 'origin/master' into separate-packge
dan-lee f810834
update versions
dan-lee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
lib/render-graphiql.ts | ||
deno_dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<h1 align="center"> | ||
<br> | ||
<img width="400" src="./logo.svg" alt="GraphQL Helix"> | ||
<br> | ||
<br> | ||
<br> | ||
</h1> | ||
|
||
> A highly evolved GraphQL HTTP Server 🧬 | ||
|
||
GraphQL Helix is a collection of utility functions for building your own GraphQL HTTP server. You can check out [Building a GraphQL server with GraphQL Helix](https://dev.to/danielrearden/building-a-graphql-server-with-graphql-helix-2k44) on DEV for a detailed tutorial on getting started. | ||
|
||
## Features | ||
|
||
- **Framework and runtime agnostic.** Use whatever HTTP library you want. GraphQL Helix works in Node, Deno and in the browser. | ||
- **HTTP first.** GraphQL Helix allows you to create a [GraphQL over HTTP](https://github.com/graphql/graphql-over-http) specification-compliant server, while exposing a single HTTP endpoint for everything from documentation to subscriptions. | ||
- **Server push and client pull.** GraphQL Helix supports real-time requests with both subscriptions and `@defer` and `@stream` directives. | ||
- **Flexible.** GraphQL Helix abstracts away logic that's common to all GraphQL HTTP servers, while leaving the implementation to you. Implement the features you want and take full control of your transport layer. | ||
- **Minimal.** No bloat. No paid platform integration. Zero dependencies outside of `graphql-js`. | ||
|
||
## Installation | ||
|
||
``` | ||
npm install graphql-helix | ||
``` | ||
|
||
``` | ||
yarn add graphql-helix | ||
``` | ||
|
||
## Basic Usage | ||
|
||
The following example shows how to integrate GraphQL Helix with Node.js using Express. This example shows how to implement all the basic features, including a GraphiQL interface, subscriptions and support for `@stream` and `@defer`. See the rest of the [examples](./examples) for implementations using other frameworks and runtimes. For implementing additional features, see the [Recipes](#Recipes) section below. | ||
|
||
```js | ||
import express, { RequestHandler } from "express"; | ||
import { getGraphQLParameters, processRequest, renderGraphiQL, shouldRenderGraphiQL, sendResult } from "../lib"; | ||
import { schema } from "./schema"; | ||
|
||
const app = express(); | ||
|
||
app.use(express.json()); | ||
|
||
app.use("/graphql", async (req, res) => { | ||
// Create a generic Request object that can be consumed by Graphql Helix's API | ||
const request = { | ||
body: req.body, | ||
headers: req.headers, | ||
method: req.method, | ||
query: req.query, | ||
}; | ||
|
||
// Determine whether we should render GraphiQL instead of returning an API response | ||
if (shouldRenderGraphiQL(request)) { | ||
res.send(renderGraphiQL()); | ||
} else { | ||
// Extract the Graphql parameters from the request | ||
const { operationName, query, variables } = getGraphQLParameters(request); | ||
|
||
// Validate and execute the query | ||
const result = await processRequest({ | ||
operationName, | ||
query, | ||
variables, | ||
request, | ||
schema, | ||
}); | ||
|
||
// processRequest returns one of three types of results depending on how the server should respond | ||
// 1) RESPONSE: a regular JSON payload | ||
// 2) MULTIPART RESPONSE: a multipart response (when @stream or @defer directives are used) | ||
// 3) PUSH: a stream of events to push back down the client for a subscription | ||
// The "sendResult" is a NodeJS-only shortcut for handling all possible types of Graphql responses, | ||
// See "Advanced Usage" below for more details and customizations available on that layer. | ||
sendResult(result, res); | ||
} | ||
}); | ||
|
||
const port = process.env.PORT || 4000; | ||
|
||
app.listen(port, () => { | ||
console.log(`GraphQL server is running on port ${port}.`); | ||
}); | ||
``` | ||
|
||
## Transports Variations | ||
|
||
The `processRequest` will return one of the following types: | ||
|
||
- `RESPONSE`: a regular JSON payload | ||
- `MULTIPART_RESPONSE`: a multipart response (when @stream or @defer directives are used) | ||
- `PUSH`: a stream of events to push back down the client for a GraphQL subscription | ||
|
||
If you GraphQL schema doesn't have the `type Subscription` defined, or the `@stream` / `@defer` / `@live` directives available, you'll get `RESPONSE` in your result payload, so you can just use `sendResult` helper to send the response data in one line of code. | ||
|
||
If you wish to have more control over you transports, you can use one of the following exported helpers: | ||
|
||
- `sendResponseResult` - matches the `RESPONSE` type. | ||
- `sendMultipartResponseResult` - matches the `MULTIPART_RESPONSE` type. | ||
- `sendPushResult` - matches the `PUSH` type. | ||
|
||
And you'll be able to construct a custom flow. Here's a quick example for customizing the response per each type of result: | ||
|
||
```ts | ||
if (result.type === "RESPONSE") { | ||
sendResponseResult(result, res); | ||
} else if (result.type === "MULTIPART_RESPONSE") { | ||
sendMultipartResponseResult(result, res); | ||
} else if (result.type === "PUSH") { | ||
sendPushResult(result, res); | ||
} | ||
``` | ||
|
||
> This way you can also disable specific responses if you wish, by return an error instead of calling the helpers. | ||
|
||
Checkout docs to learn more. |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export * from "./get-graphql-parameters.ts"; | ||
export * from "./process-request.ts"; | ||
export * from "./should-render-graphiql.ts"; | ||
export * from "./types.ts"; | ||
export * from "./errors.ts"; | ||
export * from "./send-result/node-http.ts"; | ||
export * from "./send-result/w3c.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./index.ts"; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should move this folder (
test/implementations
) topackages/graphql-helix
.