makePromise(execute(link, operation)) .then(data => { const { upvotePost } = data.data; console.log('WithLink upvotePost:', upvotePost); this.setState({ update: upvotePost }); this.getPosts(); }) .catch(error => console.log(`received error ${error}`));
// wsurl: GraphQL endpoint // query: GraphQL query (use gql`` from the 'graphql-tag' library) // variables: Query variables object const createSubscriptionObservable = (wsurl, query, variables) => { const link = new WebSocketLink(getWsClient(wsurl)); return execute(link, {query: query, variables: variables}); }
/** * e2e Testing Utils */ const startTestServer = async server => { // if using apollo-server-express... // const app = express(); // server.applyMiddleware({ app }); // const httpServer = await app.listen(0); const httpServer = await server.listen({ port: 0 }); const link = new HttpLink({ uri: `http://localhost:${httpServer.port}`, fetch, }); const executeOperation = ({ query, variables = {} }) => execute(link, { query, variables }); return { link, stop: () => httpServer.server.close(), graphql: executeOperation, }; }
makePromise(execute(link, operation)) .then(data => { const { posts } = data.data; this.setState({ posts }); }) .catch(error => console.log(`received error ${error}`));
/** * e2e Testing Utils */ const startTestServer = async server => { // if using apollo-server-express... // const app = express(); // server.applyMiddleware({ app }); // const httpServer = await app.listen(0); const httpServer = await server.listen({ port: 0 }); const link = new HttpLink({ uri: `http://localhost:${httpServer.port}`, fetch, }); const executeOperation = ({ query, variables = {} }) => execute(link, { query, variables }); return { link, stop: () => httpServer.server.close(), graphql: executeOperation, }; }
/** * e2e Testing Utils */ const startTestServer = async server => { // if using apollo-server-express... // const app = express(); // server.applyMiddleware({ app }); // const httpServer = await app.listen(0); const httpServer = await server.listen({ port: 0 }); const link = new HttpLink({ uri: `http://localhost:${httpServer.port}`, fetch, }); const executeOperation = ({ query, variables = {} }) => execute(link, { query, variables }); return { link, stop: () => httpServer.server.close(), graphql: executeOperation, }; }
/** * e2e Testing Utils */ const startTestServer = async server => { // if using apollo-server-express... // const app = express(); // server.applyMiddleware({ app }); // const httpServer = await app.listen(0); const httpServer = await server.listen({ port: 0 }); const link = new HttpLink({ uri: `http://localhost:${httpServer.port}`, fetch, }); const executeOperation = ({ query, variables = {} }) => execute(link, { query, variables }); return { link, stop: () => httpServer.server.close(), graphql: executeOperation, }; }