I have a schema that I am building with makeExecutableSchema which contains a query of the following (shortened for this issue report) form:
# The Root Query
type Query {
# Get's the user's profile with an authToken.
profile: ClientProfile!
}
# Profile snapshot of Client
type ClientProfile {
# The clientId
id: ID!
...
# An array of objects with information about the client's social identities
identities: [IdentityType]
...
}
# The OAuth2 identity provider.
enum IdentityProviderType {
GOOGLE
FACEBOOK
TWITTER
LINKEDIN
}
# Source of Identity (when account created with OAuth2 provider)
type IdentityType {
# Provider type
provider: IdentityProviderType!
# Email associated with the identity
email: Email!
}
I have a resolver of the following form:
export default {
Query: {
async profile(_, {}, { authToken }) {
/**
* Authentication
*/
const email = security.requireAuth(authToken)
/**
* Resolution
*/
const account = await accounts.find({ email })
if (!account) {
throw new GraphQLError('No account was found with the given email.', GraphQLError.codes.GRAPHQL_NOT_FOUND, 400)
}
const identities = R.reduce((ids, id) => R.append(R.omit(['accessToken'], id), ids), [], account.identities)
R.pipe(
R.omit(accounts.blackList),
R.assoc('identities', identities)
)(account)
}
}
}
So, an issue that I am having is that even though this resolver is indeed returning an appropriately formed object, including the array of IdentityType's, as can be seen below:

The executable schema is resolving identities as an array of empty objects:

And for clarification, Email type is resolved as a GraphQLEmail in another module, so this is not the issue--I am using this in many other places without problems. I also tested changing the IdentityType to
# Source of Identity (when account created with OAuth2 provider)
type IdentityType {
# Provider type
provider: String!
# Email associated with the identity
email: String!
}
But still no go.
Oh my. OK, this was a really simple problem. I am not sure why, but I was expecting the query to resolve to the complete object by default (I guess because it was a simple type without its own resolver), but obviously changing the Query to
query {
profile {
id
identities {
email,
provider
}
}
}
Fixes this issue... Bleh!!!
Thanks for posting the resolution!
Yeah, to be honest, these kinds of solutions to gotchas are pretty useful when searching for something that may be _getting_ you... haha.
I have a similar issue.
I query apps collection like this:
{
appTemplates {
id
}
}
Collection is empty, but returns this:
{
"data": {
"appTemplates": [
{
"id": null
}
]
}
}
is it possible that I get only:
{
"data": {
"appTemplates": []
}
}
:/
Most helpful comment
Oh my. OK, this was a really simple problem. I am not sure why, but I was expecting the query to resolve to the complete object by default (I guess because it was a simple type without its own resolver), but obviously changing the Query to
Fixes this issue... Bleh!!!