EasyGraphQL / easygraphql-tester

Test GraphQL queries, mutations and schemas on an easy way! 🚀
https://easygraphql.com/docs/easygraphql-tester/overview
MIT License
314 stars 34 forks source link

Remote Schema #101

Closed jrwpatterson closed 5 years ago

jrwpatterson commented 5 years ago

I'm wondering if its possible to run tests on a remote schema so that we can test clients against deployed servers?

estrada9166 commented 5 years ago

@jrwpatterson Actually it doesn't support remote schemas, but there's a workaround that can be useful using the Apollo tools described here

it'll be something like this:

'use strict'

const { introspectSchema } = require('graphql-tools')
const { HttpLink } = require('apollo-link-http')
const fetch = require('node-fetch')
const { expect } = require('chai')

const EasyGraphQLTester = require('easygraphql-tester')

const link = new HttpLink({ uri: '<YOUR_URL>', fetch });

describe('test', () => {
  let tester
  before(async () => {
    const schema = await introspectSchema(link)
    tester = new EasyGraphQLTester(schema)
  })

  it('should mock the id', () => {
    const query = `
      {
        me {
          id
          name
        }
      }
    `
    const { data } = tester.mock({
      query,
      fixture: {
        data: {
          me: {
            id: 'abc-123'
          }
        }
      }
    })

    expect(data.me.id).to.be.a('string')
    expect(data.me.name).to.be.a('string')
    expect(data.me.id).to.be.eq('abc-123')
  })
})
estrada9166 commented 5 years ago

@jrwpatterson does it works for you?

Can we close this issue?

jrwpatterson commented 5 years ago

sure I'll give it a go

estrada9166 commented 5 years ago

I'm going to close this issue, if it's needed we can open again!