Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with apollo client. #26

Closed
halallahh opened this issue Nov 4, 2016 · 4 comments
Closed

Issue with apollo client. #26

halallahh opened this issue Nov 4, 2016 · 4 comments

Comments

@halallahh
Copy link

I tried query with apollo client for graphql server that use join-monster and I got this error:

"GraphQL error: Cannot read property 'type' of undefined"

error

Not working with my own setup and join-monster-demo. I don't know this is problem with join monster or apollo client itself.

My apollo code look like this:

class App extends React.Component {
    render() {
         const { users } = this.props.data;
         console.log(users)
         return (
                // view here
         );
   }
}

const USER = gql`
{
  users {
    email
    fullName
  }
}
`;

const withData = graphql(USER)(App);
@acarl005
Copy link
Collaborator

acarl005 commented Nov 4, 2016

This is most likely a problem in Join Monster.

Can you post:

  1. the actual GraphQL query that is getting received by the server?
  2. your schema definition?

I want to try to reproduce this error. Also, if you have a public repo with the source code that I could check out, that would be great.

@halallahh
Copy link
Author

Query works with GraphiQL but not for apollo client.

graphiql

Todo:

const TodoType = new GraphQLObjectType({
    name: 'Todo',
    sqlTable: 'todos',
    uniqueKey: 'id',
    fields: () => ({
        id: {
            type: GraphQLInt,
        },
        task: {
            type: GraphQLString,
        },
        completed: {
            type: GraphQLBoolean,
        },
        comments: {
            type: new GraphQLList(CommentType),
            sqlJoin: (todoTable, commentTable) => `${todoTable}.id = ${commentTable}.todo_id`
        }
    })
});

Comment:

const CommentType = new GraphQLObjectType({
    name: 'Comment',
    sqlTable: 'comments',
    uniqueKey: 'id',
    fields: () => ({
        id: {
            type: GraphQLInt,
        },
        title: {
            type: GraphQLString,
        }
    })
});

Root:

const RootQuery = new GraphQLObjectType({
    name: 'Query',
    fields: () => ({
          todos: {
            type: new GraphQLList(TodoType),
            resolve: (parent, args, context, resolveInfo) => {
                return joinMonster(resolveInfo, context, sql => {
                    return knex.raw(sql);
                });
            }
        },
    })
});

@acarl005
Copy link
Collaborator

acarl005 commented Nov 6, 2016

Fixed in v0.5.1

The problem was that the apollo client adds some introspection to your query. This is what apollo was actually sending to the server:

{
  todos {
    task
    comments {
      title
      __typename
    }
    __typename
  }
}

The problem was that Join Monster tried to look for a user-defined __typename field. The internal fields for introspection should be ignored by Join Monster.

This is fixed. It should now work without modifying your code.

@acarl005 acarl005 closed this as completed Nov 6, 2016
@halallahh
Copy link
Author

oh, i see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants