Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added graphql-ws #301

Merged
merged 6 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added documentation
  • Loading branch information
GauBen committed Jul 7, 2022
commit b3ed9d537460c4f78387cc02630f82718b195078
2 changes: 1 addition & 1 deletion doc/.purplehaze/Layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var Layout = ({children, routes, activeRoute, prefix = ""}) => {
className: "text-gray-400 block ml-2 text-md mt-1"
}, "Autocomplete client for GraphQL"), /* @__PURE__ */ React.createElement("span", {
className: "ml-auto mr-2 text-gray-500"
}, "5.0.x"), /* @__PURE__ */ React.createElement("a", {
}, "5.1.x"), /* @__PURE__ */ React.createElement("a", {
href: "https://github.com/graphql-editor/graphql-zeus",
className: "text-purple-500",
title: "Github repository"
Expand Down
82 changes: 51 additions & 31 deletions doc/.purplehaze/ssg/markdown.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions doc/.purplehaze/ssg/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
var routes = {
"page/plugins/typedDocumentNode": "/page/plugins/typedDocumentNode",
"page/plugins/stucco": "/page/plugins/stucco",
"page/plugins/apollo": "/page/plugins/apollo",
"page/plugins/react-query": "/page/plugins/react-query",
"page/plugins/apollo": "/page/plugins/apollo",
"page/graphql/variables": "/page/graphql/variables",
"page/graphql/gql": "/page/graphql/gql",
"page/graphql/scalars": "/page/graphql/scalars",
"page/graphql/interfaces-and-unions": "/page/graphql/interfaces-and-unions",
"page/graphql/gql": "/page/graphql/gql",
"page/graphql/directives": "/page/graphql/directives",
"page/graphql/aliases": "/page/graphql/aliases",
"page/state": "/page/state",
"page/library": "/page/library",
"page/forms": "/page/forms",
"page/library": "/page/library",
"page/subscriptions": "/page/subscriptions",
"page/spec": "/page/spec",
"page/selector": "/page/selector",
"page/javascript": "/page/javascript",
Expand Down
2 changes: 2 additions & 0 deletions doc/src/markdown/basics/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ sub('subscription')({
});
```

[Read more about subscriptions](./subscriptions)

## Usage with NodeJS

Generates clients for use with Node.js
Expand Down
65 changes: 65 additions & 0 deletions doc/src/markdown/basics/subscriptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
link: subscriptions
title: Subscriptions
order: 8
category: Basics
---

## Subscriptions

Zeus supports [GraphQL subscriptions](https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md) out-of-the-box and is compatible with many popular GraphQL servers.

Two standards are supported:

- **graphql-ws**: the modern WebSocket-based transport, implemented by [the graphql-ws package](https://www.npmjs.com/package/graphql-ws). It is the standard [used by Apollo](https://www.apollographql.com/docs/react/data/subscriptions/#choosing-a-subscription-library).
- **legacy** (default): a transport based on raw WebSockets.

### Generating the client

To use [graphql-ws](https://www.npmjs.com/package/graphql-ws) as your subscription transport you'll need to do the following:

```sh
# Generate the client
zeus schema.gql ./ --subscriptions graphql-ws
# Add graphql-ws to your project's dependencies
npm install graphql-ws
```

If you want to use **legacy**, use `--subscriptions legacy` instead.

No matter what implementation you chose, usage is the same:

```ts
// Create a new Subscription with some authentication headers
const sub = Subscription('wss:https://localhost:4000/graphql', {
get headers() {
return { Authorization: `Bearer ${getToken()}` };
},
});

// Subscribe to new messages
sub('subscription')({
message: {
body: true,
},
}).on(({ message }) => {
console.log(message.body);
});
```

If you need to unsubscribe from a subscription (e.g. you are developing as Single Page App), you can do as follows:

```ts
// Subscribe to new messages
const onMessage = sub('subscription')({
message: {
body: true,
},
});
onMessage.on(({ message }) => {
console.log(message.body);
});

// Close the underlying connection
onMessage.ws.close();
```
113 changes: 35 additions & 78 deletions doc/src/purplehaze.d.ts
Original file line number Diff line number Diff line change
@@ -1,90 +1,47 @@

declare const ssg: {"envs": {"SHELL": string;
"LSCOLORS": string;
"SESSION_MANAGER": string;
"COLORTERM": string;
"XDG_CONFIG_DIRS": string;
declare const ssg: {"envs": {"PYENV_VIRTUALENV_INIT": string;
"USER": string;
"GIT_ASKPASS": string;
"SHLVL": string;
"HOME": string;
"LESS": string;
"XDG_SESSION_PATH": string;
"NVM_INC": string;
"XDG_MENU_PREFIX": string;
"OLDPWD": string;
"TERM_PROGRAM_VERSION": string;
"APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL": string;
"HISTSIZE": string;
"NODE": string;
"LC_ADDRESS": string;
"LC_NAME": string;
"SSH_AUTH_SOCK": string;
"VSCODE_IPC_HOOK_CLI": string;
"LSCOLORS": string;
"PYENV_SHELL": string;
"ZSH": string;
"PAGER": string;
"VSCODE_GIT_ASKPASS_MAIN": string;
"YARN_WRAP_OUTPUT": string;
"VSCODE_GIT_ASKPASS_NODE": string;
"COLORTERM": string;
"WSL_DISTRO_NAME": string;
"COLOR": string;
"DESKTOP_SESSION": string;
"LC_MONETARY": string;
"SSH_AGENT_PID": string;
"BAMF_DESKTOP_FILE_HINT": string;
"NO_AT_BRIDGE": string;
"EDITOR": string;
"GTK_MODULES": string;
"XDG_SEAT": string;
"PWD": string;
"GSETTINGS_SCHEMA_DIR": string;
"VOLTA_HOME": string;
"_VOLTA_TOOL_RECURSION": string;
"FORCE_COLOR": string;
"LOGNAME": string;
"XDG_SESSION_DESKTOP": string;
"QT_QPA_PLATFORMTHEME": string;
"XDG_SESSION_TYPE": string;
"PANEL_GDK_CORE_DEVICE_EVENTS": string;
"NAME": string;
"WSL_INTEROP": string;
"_": string;
"XAUTHORITY": string;
"VSCODE_GIT_ASKPASS_NODE": string;
"XDG_GREETER_DATA_DIR": string;
"MOTD_SHOWN": string;
"GDM_LANG": string;
"GTK2_RC_FILES": string;
"HOME": string;
"LANG": string;
"LC_PAPER": string;
"LS_COLORS": string;
"XDG_CURRENT_DESKTOP": string;
"FORCE_COLOR": string;
"DISABLE_WAYLAND": string;
"GIT_ASKPASS": string;
"XDG_SEAT_PATH": string;
"SAVEHIST": string;
"INIT_CWD": string;
"CHROME_DESKTOP": string;
"NVM_DIR": string;
"VSCODE_GIT_ASKPASS_EXTRA_ARGS": string;
"GEM_HOME": string;
"XDG_SESSION_CLASS": string;
"TERM": string;
"LC_IDENTIFICATION": string;
"ZSH": string;
"USER": string;
"VSCODE_GIT_IPC_HANDLE": string;
"DISPLAY": string;
"SHLVL": string;
"NVM_CD_FLAGS": string;
"PAGER": string;
"LC_TELEPHONE": string;
"ANDROID_SDK_ROOT": string;
"LC_MEASUREMENT": string;
"XDG_VTNR": string;
"XDG_SESSION_ID": string;
"XDG_RUNTIME_DIR": string;
"LC_TIME": string;
"VSCODE_GIT_ASKPASS_MAIN": string;
"QT_AUTO_SCREEN_SCALE_FACTOR": string;
"GTK3_MODULES": string;
"XDG_DATA_DIRS": string;
"GDK_BACKEND": string;
"BROWSER": string;
"PATH": string;
"GDMSESSION": string;
"ORIGINAL_XDG_CURRENT_DESKTOP": string;
"DBUS_SESSION_BUS_ADDRESS": string;
"NVM_BIN": string;
"MAIL": string;
"LC_NUMERIC": string;
"OLDPWD": string;
"NODE": string;
"DENO_INSTALL": string;
"LANG": string;
"LS_COLORS": string;
"TERM_PROGRAM": string;
"VSCODE_GIT_IPC_HANDLE": string;
"SHELL": string;
"VSCODE_GIT_ASKPASS_EXTRA_ARGS": string;
"GPG_TTY": string;
"PWD": string;
"VIRTUAL_ENV_DISABLE_PROMPT": string;
"HOSTTYPE": string;
"INIT_CWD": string;
"WSLENV": string;
"EDITOR": string;
"PATH_PREFIX": string};
"config": {"out": string;
"in": string;
Expand Down
Loading