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

Trouble adding @paginate directives #120

Closed
tsiege opened this issue Jun 16, 2020 · 3 comments
Closed

Trouble adding @paginate directives #120

tsiege opened this issue Jun 16, 2020 · 3 comments
Labels
question Further information is requested

Comments

@tsiege
Copy link
Contributor

tsiege commented Jun 16, 2020

I've added @paginate and it breaks on many to many relationships, and I'm not sure if I'm using it incorrectly for other custom resolvers.

  type Query @sqlmancer(dialect: POSTGRES, transformFieldNames: SNAKE_CASE, customScalars: { JSON: ["JSON", "JSONObject"], Date: ["DateTime"] }) {
    post(slug: String!): Post
    posts: [Post!]! @paginate
  }
  type Post @model(table: "posts", pk: "id") {
    id: ID!
    mobiledoc: String!
    slug: String!
    title: String!
    createdAt: String!
    publishedAt: String
    authors: [Author!]! @relate(
      through: "posts_authors",
      on: [{ from: "id", to: "post_id" }, { from: "author_id", to: "id" }]
    ) @paginate
  }
  type Author @model(table: "authors", pk: "id") {
    id: ID!
    name: String!
    email: String!
    posts: [Post!]! @relate(
      through: "posts_authors",
      on: [{ from: "id", to: "author_id" }, { from: "post_id", to: "id" }]
    )
  }
{
    Query: {
      async post(parent, args, ctx, info) {
        return client.models.Post.findOne()
          .where({ slug: { equal: args.slug } })
          .resolveInfo(info)
          .execute()
      },
      async posts(parent, args, ctx, info) {
        return client.models.Post.findMany()
          .orderBy([{ publishedAt: 'DESC' }])
          .resolveInfo(info)
          .execute()
      }
    },
    Post: {},
    Author: {},
  }

For both I'm seeing errors about results not returning a non-null field for <TypeName>Page.results. I'm not sure if maybe there's something I need to do in the resolvers or not to make this work but returning { results: <some data> }

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field PostPage.results.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "posts",
        "results"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Cannot return null for non-nullable field PostPage.results.",
            "    at completeValue (/Users/tristan/code/thedipp/api.thedipp.com/node_modules/graphql/execution/execute.js:560:13)",
            "    at completeValueCatchingError (/Users/tristan/code/thedipp/api.thedipp.com/node_modules/graphql/execution/execute.js:495:19)",
            "    at resolveField (/Users/tristan/code/thedipp/api.thedipp.com/node_modules/graphql/execution/execute.js:435:10)",
            "    at executeFields (/Users/tristan/code/thedipp/api.thedipp.com/node_modules/graphql/execution/execute.js:275:18)",
            "    at collectAndExecuteSubfields (/Users/tristan/code/thedipp/api.thedipp.com/node_modules/graphql/execution/execute.js:713:10)",
            "    at completeObjectValue (/Users/tristan/code/thedipp/api.thedipp.com/node_modules/graphql/execution/execute.js:703:10)",
            "    at completeValue (/Users/tristan/code/thedipp/api.thedipp.com/node_modules/graphql/execution/execute.js:591:12)",
            "    at completeValue (/Users/tristan/code/thedipp/api.thedipp.com/node_modules/graphql/execution/execute.js:557:21)",
            "    at /Users/tristan/code/thedipp/api.thedipp.com/node_modules/graphql/execution/execute.js:492:16",
            "    at processTicksAndRejections (internal/process/task_queues.js:97:5)"
          ]
        }
      }
    }
  ],
  "data": null
}
@danielrearden
Copy link
Owner

@tsiege Add pagination: OFFSET to @relate

authors: [Author!]! @relate(
      through: "posts_authors",
      on: [{ from: "id", to: "post_id" }, { from: "author_id", to: "id" }]
      pagination: OFFSET
    ) @paginate

@tsiege
Copy link
Contributor Author

tsiege commented Jun 16, 2020

Thank you @danielrearden! I realized I was misreading the documentation as well. Thanks so much for your help

@danielrearden
Copy link
Owner

Apologies it's not clearer in the docs :( To be honest, the current way of adding pagination is still overly complicated. It's yet another thing I hope we can fix by moving away from a schema-first approach.

@danielrearden danielrearden added the question Further information is requested label Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants