Skip to content

Commit

Permalink
rollback of temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Aug 23, 2024
1 parent 78cb500 commit 3c48be0
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 195 deletions.
60 changes: 46 additions & 14 deletions packages/graphiql/cypress/e2e/incremental-delivery.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,36 @@ describeOrSkip('IncrementalDelivery support via fetcher', () => {
const mockStreamSuccess = {
data: {
streamable: [
{ text: 'Hi' },
{ text: '你好' },
{ text: 'Hola' },
{ text: 'أهلاً' },
{ text: 'Bonjour' },
{ text: 'سلام' },
{ text: '안녕' },
{ text: 'Ciao' },
{ text: 'हेलो' },
{ text: 'Здорово' },
{
text: 'Hi',
},
{
text: '你好',
},
{
text: 'Hola',
},
{
text: 'أهلاً',
},
{
text: 'Bonjour',
},
{
text: 'سلام',
},
{
text: '안녕',
},
{
text: 'Ciao',
},
{
text: 'हेलो',
},
{
text: 'Здорово',
},
],
},
};
Expand Down Expand Up @@ -121,10 +141,22 @@ describeOrSkip('IncrementalDelivery support via fetcher', () => {
person: {
name: 'Mark',
friends: [
{ name: 'James', age: 1000 },
{ name: 'Mary', age: 1000 },
{ name: 'John', age: 1000 },
{ name: 'Patrica', age: 1000 },
{
name: 'James',
age: 1000,
},
{
name: 'Mary',
age: 1000,
},
{
name: 'John',
age: 1000,
},
{
name: 'Patrica',
age: 1000,
},
],
age: 1000,
},
Expand Down
1 change: 0 additions & 1 deletion packages/graphiql/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Cypress.Commands.add('dataCy', value => {
});

Cypress.Commands.add('clickExecuteQuery', () => {
cy.wait(500)
return cy.get('.graphiql-execute-button').click();
});

Expand Down
4 changes: 0 additions & 4 deletions packages/graphiql/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
}
</style>
<!--vite-replace-start-->
<script
type="text/javascript"
src="https://unpkg.com/graphql-sse/umd/graphql-sse.min.js"
></script>
<script
crossorigin
src="https://unpkg.com/react@18/umd/react.production.min.js"
Expand Down
2 changes: 0 additions & 2 deletions packages/graphiql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"react-dom": "^16.8.0 || ^17 || ^18"
},
"devDependencies": {
"cors": "^2.8.5",
"@graphiql/toolkit": "^0.10.0",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/react": "14.0.0",
Expand All @@ -58,7 +57,6 @@
"cypress": "^13.13.2",
"express": "^4.19.2",
"graphql": "^17.0.0-alpha.7",
"graphql-sse": "^2.5.3",
"graphql-helix": "^1.13.0",
"graphql-subscriptions": "^2.0.0",
"postcss": "8.4.31",
Expand Down
81 changes: 14 additions & 67 deletions packages/graphiql/resources/renderExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,81 +62,28 @@ function updateURL() {
history.replaceState(null, null, `?${newSearch}`);
}

function getSchemaUrl() {
const isDev = /localhost$/.test(location.hostname);

if (isDev) {
return '/graphql';
}
return '/.netlify/functions/graphql';
}

// Render <GraphiQL /> into the body.
// See the README in the top level of this module to learn more about
// how you can customize GraphiQL by providing different values or
// additional child elements.
const root = ReactDOM.createRoot(document.getElementById('graphiql'));

const { version: graphqlVersion } = GraphiQL.GraphQL;

const url = /localhost$/.test(location.hostname)
? '/graphql'
: '/.netlify/functions/graphql';

const fetcher = GraphiQL.createFetcher({
url,
subscriptionUrl: 'ws://localhost:8081/subscriptions',
});

const sseClient = graphqlSse.createClient({
singleConnection: true, // or use false if you have an HTTP/2 server
url: 'http://localhost:8080/graphql/stream',
retryAttempts: 0,
lazy: false, // connect as soon as the page opens
});

function subscribe(payload) {
let deferred = null;
const pending = [];
let throwMe = null;
let done = false;

const dispose = sseClient.subscribe(payload, {
next(data) {
pending.push(data);
deferred?.resolve(false);
},
error(err) {
throwMe = err;
deferred?.reject(throwMe);
},
complete() {
done = true;
deferred?.resolve(true);
},
});

return {
[Symbol.asyncIterator]() {
return this;
},
async next() {
if (done) {
return { done: true, value: undefined };
}
if (throwMe) {
throw throwMe;
}
if (pending.length) {
return { value: pending.shift() };
}
return (await new Promise(
(resolve, reject) => (deferred = { resolve, reject }),
))
? { done: true, value: undefined }
: { value: pending.shift() };
},
async return() {
dispose();
return { done: true, value: undefined };
},
};
}
const graphqlVersion = GraphiQL.GraphQL.version;

root.render(
React.createElement(GraphiQL, {
fetcher: subscribe,
fetcher: GraphiQL.createFetcher({
url: getSchemaUrl(),
subscriptionUrl: 'ws://localhost:8081/subscriptions',
}),
query: parameters.query,
variables: parameters.variables,
headers: parameters.headers,
Expand Down
31 changes: 0 additions & 31 deletions packages/graphiql/test/beforeDevServer.js

This file was deleted.

29 changes: 1 addition & 28 deletions packages/graphiql/test/e2e-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import {
processRequest,
sendResult,
} from 'graphql-helix'; // update when `graphql-http` is upgraded to support multipart requests for incremental delivery https://github.com/graphql/graphiql/pull/3682#discussion_r1715545279
import { createHandler } from 'graphql-sse/lib/use/express';
import cors from 'cors';

import { schema, sseSchema } from './schema.js';
import { schema } from './schema.js';
import { customExecute } from './execute.js';

const app = express();
Expand All @@ -47,31 +45,6 @@ async function handler(req, res) {
sendResult(result, res);
}

// Create the GraphQL over SSE handler
const sseHandler = createHandler({ schema: sseSchema });

app.use('/graphql/stream', (req, res, next) => {
// Fixes
// Access to fetch at 'http://localhost:8080/graphql/stream' from origin 'http://localhost:5173' has been blocked by
// CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'
// header is present on the requested resource. If an opaque response serves your needs, set the request's mode to
// 'no-cors' to fetch the resource with CORS disabled.

// CORS headers
res.header('Access-Control-Allow-Origin', '*'); // restrict it to the required domain
res.header("Access-Control-Allow-Methods", "GET,PUT,POST");
// Set custom headers for CORS
res.header('Access-Control-Allow-Headers', 'content-type,x-graphql-event-stream-token');

if (req.method === 'OPTIONS') {
return res.status(200).end();
}
next();
});

// Serve all methods on `/graphql/stream`
app.use('/graphql/stream', sseHandler);

// Server
app.use(express.json());

Expand Down
26 changes: 0 additions & 26 deletions packages/graphiql/test/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,29 +397,3 @@ export const schema = new GraphQLSchema({
description: 'This is a test schema for GraphiQL',
directives,
});

export const sseSchema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
hello: {
type: GraphQLString,
resolve: () => 'world',
},
},
}),
subscription: new GraphQLObjectType({
name: 'Subscription',
fields: {
greetings: {
type: GraphQLString,
subscribe: async function* () {
for (const hi of ['Hi', 'Bonjour', 'Hola', 'Ciao', 'Zdravo']) {
await sleep(500)
yield { greetings: hi };
}
},
},
},
}),
});
12 changes: 5 additions & 7 deletions packages/graphiql/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,23 @@ const esmConfig = defineConfig({
open: false,
proxy: {
'/graphql': 'http://localhost:8080',
'/graphql/stream': 'http://localhost:8080/graphql/stream',
'/subscriptions': {
target: 'ws://localhost:8081',
ws: true,
},
},
},
plugins: [htmlPlugin(), commonjs(), dts({ rollupTypes: true })],
plugins: [htmlPlugin(), dts({ rollupTypes: true })],
});

function htmlPlugin(): PluginOption {
const htmlForVite = /* HTML */ `
<script type="module">
import React from "react";
import ReactDOM from "react-dom/client";
import GraphiQL from "./src/cdn";
import { createClient } from "graphql-sse";
import React from 'react';
import ReactDOM from 'react-dom/client';
import GraphiQL from './src/cdn';
Object.assign(globalThis,{ React, ReactDOM, GraphiQL, graphqlSse: { createClient } });
Object.assign(globalThis, { React, ReactDOM, GraphiQL });
</script>
<link href="/src/style.css" rel="stylesheet" />
`;
Expand Down
17 changes: 2 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7287,14 +7287,6 @@ core-util-is@^1.0.2, core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==

cors@^2.8.5:
version "2.8.5"
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
dependencies:
object-assign "^4"
vary "^1"

cosmiconfig-toml-loader@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/cosmiconfig-toml-loader/-/cosmiconfig-toml-loader-1.0.0.tgz#0681383651cceff918177debe9084c0d3769509b"
Expand Down Expand Up @@ -10187,11 +10179,6 @@ graphql-http@^1.22.1:
resolved "https://registry.yarnpkg.com/graphql-http/-/graphql-http-1.22.1.tgz#3857ac75366e55db189cfe09ade9cc4c4f2cfd09"
integrity sha512-4Jor+LRbA7SfSaw7dfDUs2UBzvWg3cKrykfHRgKsOIvQaLuf+QOcG2t3Mx5N9GzSNJcuqMqJWz0ta5+BryEmXg==

graphql-sse@^2.5.3:
version "2.5.3"
resolved "https://registry.yarnpkg.com/graphql-sse/-/graphql-sse-2.5.3.tgz#c3557803f2db306d8ac87fd3bc089b6d4bac8353"
integrity sha512-5IcFW3e7fPOG7oFkK1v3X1wWtCJArQKB/H1UJeNotjy7a/9EYA5K+EiHJF1BiDSVNx7y64bd0FlDETrNBSvIHQ==

graphql-subscriptions@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/graphql-subscriptions/-/graphql-subscriptions-2.0.0.tgz#11ec181d475852d8aec879183e8e1eb94f2eb79a"
Expand Down Expand Up @@ -13827,7 +13814,7 @@ nwsapi@^2.2.0:
resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.5.tgz#a52744c61b3889dd44b0a158687add39b8d935e2"
integrity sha512-6xpotnECFy/og7tKSBVmUNft7J3jyXAka4XvG6AUhFWRz+Q/Ljus7znJAA3bxColfQLdS+XsjoodtJfCgeTEFQ==

object-assign@^4, object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
Expand Down Expand Up @@ -17532,7 +17519,7 @@ value-or-promise@^1.0.11, value-or-promise@^1.0.12:
resolved "https://registry.yarnpkg.com/value-or-promise/-/value-or-promise-1.0.12.tgz#0e5abfeec70148c78460a849f6b003ea7986f15c"
integrity sha512-Z6Uz+TYwEqE7ZN50gwn+1LCVo9ZVrpxRPOhOLnncYkY1ZzOYtrX8Fwf/rFktZ8R5mJms6EZf5TqNOMeZmnPq9Q==

vary@^1, vary@~1.1.2:
vary@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=
Expand Down

0 comments on commit 3c48be0

Please sign in to comment.