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

Can't use AWS Scalars #68

Closed timgivois closed 5 years ago

timgivois commented 5 years ago

when using AWS Scalars like AWSURL the test doesn't pass

estrada9166 commented 5 years ago

@timgivois Thanks for creating the issue! Can you share me the query/mutation you're doing, the error that it returns and if it's possible the schema, so I can try it locally!

Thanks!

timgivois commented 5 years ago

sure:

// schema.graphl

type User {
    id: ID!
    username: AWSEmail!
    image: AWSURL
}

type Query {
    users: [User]!
}

// schema.test.js

import fs from 'fs'
import EasyGraphQLTester from 'easygraphql-tester'

describe('Graphql Server', () => {
    beforeAll(() => {
        const schema = fs.readFileSync('schema.graphql', 'utf8')
        tester = new EasyGraphQLTester([schema, AWSScalar])
    })
    it('returns users', () => {
        const query = `
          query {
            users {
                id,
                email,
                image
             }
           }
        `
        tester.test(true, query)
    })
})

And the error is:

    >      |     tester = new EasyGraphQLTester(schema)
            |                    ^
    Type "AWSURL" not found in document.
timgivois commented 5 years ago

Link to AppSync Scalars: https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html

estrada9166 commented 5 years ago

Can you try adding scalar AWSURL on your schema, please!

The reason for this error is because the scalar definition is not found in the schema.

timgivois commented 5 years ago

yes, I created the scalars in a separate file that I'll import just for testing. I believe that this could be added to the library. I can create the PR for it ;)

estrada9166 commented 5 years ago

That will be awesome!! Thanks!

Also, quick question... the separate file with the scalars is a .graphql file? in case that yes, you can do tester = new EasyGraphQLTester([schema, scalars])

timgivois commented 5 years ago

yes, that's what I was doing after reading the docs :D

estrada9166 commented 5 years ago

That's great!! does it work as expected?

timgivois commented 5 years ago

Yes it works as expected @estrada9166 :)

estrada9166 commented 5 years ago

@timgivois Can we close this issue?

timgivois commented 5 years ago

I just saw that I'm having another issue now:

  ● Graphql Server › User part › adds a User

    username argument is not type AWSEmail

      65 |         }
      66 |       `
    > 67 |       tester.test(true, query, {
         |              ^
      68 |         newUser
      69 |       })
      70 |     })

      at validateInputType (node_modules/easygraphql-tester/utils/validator.js:276:15)
      at validateInputArg (node_modules/easygraphql-tester/utils/validator.js:257:9)
estrada9166 commented 5 years ago

@timgivois Would you like to create a PR? I can tell you how it'll be solved! or I can push the changes if you want!

timgivois commented 5 years ago

well, I saw that validator.js doesn't take into account scalars. I'm not sure what could be the best way to modify that line of code: if we saw that we receive a String and it has a scalar type it should pass, right?

estrada9166 commented 5 years ago

@timgivois if you want I can guide you throw it, so you can create the PR!!

timgivois commented 5 years ago

Thanks, that will be great. @estrada9166

estrada9166 commented 5 years ago

That awesome!! We need to do multiple things!

How to do it?

I tried to explain with the more details possible, but if can help you with more details or something else, it'll be a pleasure for me :)!!

timgivois commented 5 years ago

Sure @estrada9166, I'll dive into the code this days. If anything comes up I'll directly reach you!