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

Test mutation with input type Upload #109

Closed harked closed 3 years ago

harked commented 5 years ago

Hi, I want to test my mutation which have input type Upload. How to do that with EasyGraphQL?

I know we can pass the expected input on the third parameter (after Call test from tester).

const EasyGraphQLTester = require('easygraphql-tester')
const fs = require('fs')
const path = require('path')

const schemaCode = fs.readFileSync(path.join(__dirname, 'schema', 'schema.gql'), 'utf8')
const tester = new EasyGraphQLTester(schemaCode)

const mutation = `
  mutation CreateUser{
    createUser {
      email
    }
  }
`
tester.test(true, mutation, {
  banner: '',
  username: 'test',
  fullName: 'test',
  password: 'test'
})

on that above case.. if banner is input type Upload, how to do that in easygraphql?

estrada9166 commented 5 years ago

@harked Thanks for creating this issue!

For the moment custom scalars are not supported on the input, would you like to create a PR for this?

IvanVilla1585 commented 5 years ago

@harked @estrada9166 I'm working on it.

estrada9166 commented 5 years ago

@harked sorry, I think I misunderstood the issue.

If the type Upload is defined in the schema as a scalar you can pass any value there, so it should be something like this:

tester.test(true, mutation, {
  banner: 'custom-data',
  username: 'test',
  fullName: 'test',
  password: 'test'
})

Another thing is that you have to set the mutation with the expected input, I mean:

const mutation = `
  mutation CreateUser($banner: Upload!, $username: String!, $fullName: String!, $password: String!){
    createUser(banner: $banner, username: $username, fullName: $fullname, password: $password) {
      email
    }
  }
`

or

const mutation = `
  mutation CreateUser($input: CreateUserInput!){
    createUser(input: $input) {
      email
    }
  }
`

Also, because you're not wrapping it in any test runner if it's correct it's not gonna show anything, but if you change the type of the value in one field on the mutation, it's gonna return an error.

You can use .mock, if you want to have a mock of the mutation.

const mock = tester.mock({
  query: mutation,
  variables: {
    banner: 'custom-data',
    username: 'test',
    fullName: 'test',
    password: 'test'
  }
})

If your mutation expect an input that is going to have different fields, you should pass the variables as

tester.test(true, mutation, {
  input: {
    banner: 'custom-data',
    username: 'test',
    fullName: 'test',
    password: 'test'
  }
})
estrada9166 commented 5 years ago

@harked did this work for you? can we close this issue?

harked commented 3 years ago

@estrada9166 sorry for so late reply. It works for me. Thanks. I'll close this issue now.