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

Add support for subscriptions in GraphiQL #320

Merged
merged 21 commits into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
cd1c19d
Add support for AWS Lambda
NeoReyad Dec 14, 2016
789a4dd
Update README and Changelog
NeoReyad Dec 17, 2016
2ff57f5
Add the restify variant to README
NeoReyad Jan 25, 2017
63bcd46
Add instructions for deploying the Lambda Function
NeoReyad Jan 31, 2017
ca00a96
Update CONTRIBUTING.md
helfer Jan 31, 2017
b3a00ff
chore(package):fix badges in readme after org rename.
DxCx Feb 3, 2017
9eab90d
Changes "apollo server" to "Graphql Server"
RafaelCosman Feb 4, 2017
38e5932
chore(package): update lerna back to upstream package
DxCx Feb 2, 2017
8b9e433
chore(package): update internal depenecies
DxCx Feb 2, 2017
e2c4258
fix(tests): fixed typo in testcase of formatError
DxCx Feb 3, 2017
c4fabe3
added support for subscriptions
Urigo Feb 28, 2017
68e4a35
feat(subscriptions): added subscriptions for graphiql
Urigo Mar 9, 2017
54443b8
feat(subscriptions): added subscriptions graphiql to all server types
Urigo Mar 9, 2017
af86de8
feat(subscriptions): dont include transport if not using subscriptions
Urigo Mar 18, 2017
99d1bcf
feat(subscriptions): updated packages imports
Urigo Mar 26, 2017
d5053c9
feat(subscriptions): updated fetcher version
Urigo Mar 26, 2017
12c8a02
Merge branch 'master' into feat/subscriptions-graphiql
Urigo Mar 28, 2017
23b534a
feat(subscriptions): added missing "?" to props definition
Urigo Mar 28, 2017
7634b34
Merge branch 'master' into feat/subscriptions-graphiql
Urigo Mar 28, 2017
eb13a5d
Merge branch 'feat/subscriptions-graphiql' of github.com:Urigo/graphq…
Urigo Mar 28, 2017
f7e2fb0
Merge branch 'master' into feat/subscriptions-graphiql
DxCx Mar 30, 2017
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### VNEXT

* Restify: Fix for calling next() (([@jadkap](https://github.com/jadkap)) on [#285](https://github.com/apollostack/graphql-server/pull/285))
* Add AWS Lambda Integration [#101](https://github.com/apollostack/graphql-server/issues/101)
* Restify: Fix for calling next() ([@jadkap](https://github.com/jadkap)) on [#285](https://github.com/apollostack/graphql-server/pull/285)
* Update GraphiQL to version 0.9.1 ([@ephemer](https://github.com/ephemer)) on [#293](https://github.com/apollostack/graphql-server/pull/293)
* Add AWS Lambda Integration [#101](https://github.com/apollostack/graphql-server/issues/101)
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-server-express/src/expressApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function graphiqlExpress(options: GraphiQL.GraphiQLData) {

const graphiQLString = GraphiQL.renderGraphiQL({
endpointURL: options.endpointURL,
subscriptionsEndpoint: options.subscriptionsEndpoint,
query: query || options.query,
variables: q.variables && JSON.parse(q.variables) || options.variables,
operationName: operationName || options.operationName,
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-server-hapi/src/hapiApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function renderGraphiQL(route, graphiqlParams: any, reply) {
const graphiqlOptions = route.settings.plugins['graphiql'];
const graphiQLString = GraphiQL.renderGraphiQL({
endpointURL: graphiqlOptions.endpointURL,
subscriptionsEndpoint: graphiqlOptions.subscriptionsEndpoint,
query: graphiqlParams.query || graphiqlOptions.query,
variables: graphiqlParams.variables && JSON.parse(graphiqlParams.variables) || graphiqlOptions.variables,
operationName: graphiqlParams.operationName || graphiqlOptions.operationName,
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-server-koa/src/koaApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function graphiqlKoa(options: GraphiQL.GraphiQLData) {

const graphiQLString = GraphiQL.renderGraphiQL({
endpointURL: options.endpointURL,
subscriptionsEndpoint: options.subscriptionsEndpoint,
query: query || options.query,
variables: q.variables && JSON.parse(q.variables) || options.variables,
operationName: operationName || options.operationName,
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-server-lambda/src/lambdaApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export function graphiqlLambda(options: GraphiQL.GraphiQLData) {

const graphiQLString = GraphiQL.renderGraphiQL({
endpointURL: options.endpointURL,
subscriptionsEndpoint: options.subscriptionsEndpoint,
query: query || options.query,
variables: q.variables && JSON.parse(variables) || options.variables,
operationName: operationName || options.operationName,
Expand Down
57 changes: 38 additions & 19 deletions packages/graphql-server-module-graphiql/src/renderGraphiQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

export type GraphiQLData = {
endpointURL: string,
subscriptionsEndpoint?: string,
query?: string,
variables?: Object,
operationName?: string,
Expand All @@ -38,6 +39,8 @@ function safeSerialize(data) {

export function renderGraphiQL(data: GraphiQLData): string {
const endpointURL = data.endpointURL;
const subscriptionsEndpoint = data.subscriptionsEndpoint;
const usingSubscriptions = !!subscriptionsEndpoint;
const queryString = data.query;
const variablesString =
data.variables ? JSON.stringify(data.variables, null, 2) : null;
Expand Down Expand Up @@ -66,6 +69,10 @@ export function renderGraphiQL(data: GraphiQLData): string {
<script src="//cdn.jsdelivr.net/react/15.0.0/react.min.js"></script>
<script src="//cdn.jsdelivr.net/react/15.0.0/react-dom.min.js"></script>
<script src="//cdn.jsdelivr.net/graphiql/${GRAPHIQL_VERSION}/graphiql.min.js"></script>
${usingSubscriptions ?
'<script src="//unpkg.com/subscriptions-transport-ws@0.5.4/browser/client.js"></script>' +
'<script src="//unpkg.com/graphiql-subscriptions-fetcher@0.0.2/browser/client.js"></script>'
: ''}
</head>
<body>
<script>
Expand Down Expand Up @@ -97,28 +104,40 @@ export function renderGraphiQL(data: GraphiQLData): string {
otherParams[k] = parameters[k];
}
}

var fetcher;

if (${usingSubscriptions}) {
var subscriptionsClient = new window.SubscriptionsTransportWs.SubscriptionClient('${subscriptionsEndpoint}', {
reconnect: true
});
fetcher = window.GraphiQLSubscriptionsFetcher.graphQLFetcher(subscriptionsClient, graphQLFetcher);
} else {
fetcher = graphQLFetcher;
}

// We don't use safe-serialize for location, because it's not client input.
var fetchURL = locationQuery(otherParams, '${endpointURL}');

// Defines a GraphQL fetcher using the fetch API.
function graphQLFetcher(graphQLParams) {
return fetch(fetchURL, {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
${passHeader}
},
body: JSON.stringify(graphQLParams),
credentials: 'include',
}).then(function (response) {
return response.text();
}).then(function (responseBody) {
try {
return JSON.parse(responseBody);
} catch (error) {
return responseBody;
}
});
return fetch('/graphql', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(graphQLParams),
credentials: 'include',
}).then(function (response) {
return response.text();
}).then(function (responseBody) {
try {
return JSON.parse(responseBody);
} catch (error) {
return responseBody;
}
});
}
// When the query and variables string is edited, update the URL bar so
// that it can be easily shared.
Expand All @@ -140,7 +159,7 @@ export function renderGraphiQL(data: GraphiQLData): string {
// Render <GraphiQL /> into the body.
ReactDOM.render(
React.createElement(GraphiQL, {
fetcher: graphQLFetcher,
fetcher: fetcher,
onEditQuery: onEditQuery,
onEditVariables: onEditVariables,
onEditOperationName: onEditOperationName,
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-server-restify/src/restifyApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function graphiqlRestify(options: GraphiQL.GraphiQLData) {

const graphiQLString = GraphiQL.renderGraphiQL({
endpointURL: options.endpointURL,
subscriptionsEndpoint: options.subscriptionsEndpoint,
query: query || options.query,
variables: q.variables && JSON.parse(q.variables) || options.variables,
operationName: operationName || options.operationName,
Expand Down