Closed timgivois closed 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!
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.
Link to AppSync Scalars: https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html
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.
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 ;)
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])
yes, that's what I was doing after reading the docs :D
That's great!! does it work as expected?
Yes it works as expected @estrada9166 :)
@timgivois Can we close this issue?
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)
@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!
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?
@timgivois if you want I can guide you throw it, so you can create the PR!!
Thanks, that will be great. @estrada9166
That awesome!! We need to do multiple things!
We should validate if the argument is scalar
, so, we have the parsed schema (schema
) and each argument has a type
property (will be the nested type), so we can search for that type
on the schema, if there is one check the type if it's
'ScalarTypeDefinition'
so if it's it means that isScalar = true
Now on validateInputArg
we have to do multiple things:
filteredArg
can be undefined
but sometimes it should not be that because schemaVar
can be an object but it doesn't mean is a nested object that we can access like schemaVar[arg.name]
, so we should validate if filteredArg
is undefined, lets check if it's an object that contains kind
and use getArgValue(schemaVar)
to get the argument value... when is this happening? This is the caseisScalar
from here because, now if it's undefined
is because that argument is missingisScalar
before validating the typeof
of the argument, so if it's a scalar
we should returnI 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 :)!!
Sure @estrada9166, I'll dive into the code this days. If anything comes up I'll directly reach you!
when using AWS Scalars like
AWSURL
the test doesn't pass