mickhansen / graphql-sequelize

GraphQL & Relay for MySQL & Postgres via Sequelize
MIT License
1.9k stars 172 forks source link

Usage with Apollo v2 #658

Closed mschipperheyn closed 5 years ago

mschipperheyn commented 5 years ago

Trying to use this with Apollo V2. I have modeled my graphql structure in line with Relay (Connections, Edges, Nodes), but resolver fails because the resulting graphql structure seems a bit different

https://github.com/mickhansen/graphql-sequelize/blob/bbf74bd0d81e0efc53724c5626958add7cc4b2db/src/relay.js#L117

The code expects connectionType._fields.edges.type.ofType._fields.node.type;

But what it is looks like this:

screenshot 2019-02-27 at 20 30 58

The nested _fields are not there.

My Graphql looks like this:

         type User implements Node & Searchable {
        id: ID!
        username: String
        email: String!
        searchText: String
        pets: PetConnection
        createdAt: DateTime!
        updatedAt: DateTime
    }
    type UserEdge implements Edge {
        cursor: String!
        node: User!
    }
    type UserConnection implements Connection {
        edges: [UserEdge]!
        pageInfo: PageInfo!
        totalCount: Int!
    }

Any suggestions here?

mickhansen commented 5 years ago

https://facebook.github.io/relay/docs/en/graphql-server-specification.html

edges is not supposed to be non null per the spec

mschipperheyn commented 5 years ago

Thanks, I figured it out. I was thrown off by the examples in the README that use the non string version of schema definition. The other thing that caught me was the dataloader and the fact that I had to specify a type at the root to be able to load associations (the example does cover that). It's mostly newbie problems and understanding the basic concepts. However, I would recommend replacing the example on the homepage with a string version like in the example. For me, some conceptual explanation also would have helped, although that might be more on the graphl than the graphql-sequelize side.

mickhansen commented 5 years ago

The README examples are from when pretty much only graphql-js existed as a reference implementation. PR to improve documentation is always welcome, it's usually easier as a relative beginner to provide good documentation examples.