github.com/xzyfer/gqlgen@v0.7.2/integration/integration-test.js (about) 1 import {InMemoryCache} from "apollo-cache-inmemory"; 2 import {HttpLink} from "apollo-link-http"; 3 import {ApolloClient} from "apollo-client"; 4 import fetch from "node-fetch"; 5 import gql from 'graphql-tag'; 6 7 var uri = process.env.SERVER_URL || 'http://localhost:8080/query'; 8 9 const client = new ApolloClient({ 10 link: new HttpLink({uri, fetch}), 11 cache: new InMemoryCache(), 12 defaultOptions: { 13 watchQuery: { 14 fetchPolicy: 'network-only', 15 errorPolicy: 'ignore', 16 }, 17 query: { 18 fetchPolicy: 'network-only', 19 errorPolicy: 'all', 20 }, 21 }, 22 }); 23 24 describe('Json', () => { 25 it('should follow json escaping rules', async () => { 26 let res = await client.query({ 27 query: gql`{ jsonEncoding }`, 28 }); 29 30 expect(res.data.jsonEncoding).toBe("σΎ“"); 31 expect(res.errors).toBe(undefined); 32 }); 33 }); 34 35 describe('Input defaults', () => { 36 it('should pass default values to resolver', async () => { 37 let res = await client.query({ 38 query: gql`{ date(filter:{value: "asdf"}) }`, 39 }); 40 41 expect(res.data.date).toBe(true); 42 expect(res.errors).toBe(undefined); 43 }); 44 }); 45 46 describe('Errors', () => { 47 it('should respond with correct paths', async () => { 48 let res = await client.query({ 49 query: gql`{ path { cc:child { error } } }`, 50 }); 51 52 expect(res.errors[0].path).toEqual(['path', 0, 'cc', 'error']); 53 expect(res.errors[1].path).toEqual(['path', 1, 'cc', 'error']); 54 expect(res.errors[2].path).toEqual(['path', 2, 'cc', 'error']); 55 expect(res.errors[3].path).toEqual(['path', 3, 'cc', 'error']); 56 }); 57 58 it('should use the error presenter for custom errors', async () => { 59 let res = await client.query({ 60 query: gql`{ error(type: CUSTOM) }`, 61 }); 62 63 expect(res.errors[0].message).toEqual('User message'); 64 }); 65 66 it('should pass through for other errors', async () => { 67 let res = await client.query({ 68 query: gql`{ error(type: NORMAL) }`, 69 }); 70 71 expect(res.errors[0].message).toEqual('Normal error'); 72 }); 73 });