graphql

pcj 2019-05-30T00:04:29.007200Z

@currentoor you can use an introspection query for that https://graphql.org/learn/introspection/

currentoor 2019-05-30T00:04:47.007400Z

ah thanks @pcj

devth 2019-05-30T17:10:25.000700Z

is anyone using cursor based pagination with lacinia? https://graphql.org/learn/pagination/

sashton 2019-05-30T17:22:38.000900Z

Yes, it works well for some of our use cases.

devth 2019-05-30T17:23:06.001100Z

cool. is your schema public/open source? curious how to describe it

sashton 2019-05-30T17:25:50.001300Z

It’s not public. But here is basically what it looks like:

:PagedFoo
  {:fields
   {:foo_list {:type (list :Foo)}
    :next_page_cursor {:type String}}}

devth 2019-05-30T17:26:30.001500Z

thanks. i was trying to figure out if "Paged" could be a generic type

devth 2019-05-30T17:26:35.001700Z

not sure the concept even exists in lacinia

devth 2019-05-30T17:26:42.001900Z

so that i could have many different types of Paged things

sashton 2019-05-30T17:27:01.002100Z

I see in that link you posted, they chose to put PageInfo in friends, whereas we chose to wrap our data object in the paging.

devth 2019-05-30T17:27:23.002300Z

yep

sashton 2019-05-30T17:28:49.002500Z

I haven’t thought deeply about their approach, but one possible problem I see is that now the Friend type has to know about paging. Maybe that makes sense, but for us at least we have paths to get single Foo objects, so paging wouldn’t make sense in that context

devth 2019-05-30T17:29:09.002700Z

good point

sashton 2019-05-30T17:29:36.002900Z

I think also that ours could be written:

:PagedFoo
  {:fields
   {:foo_list {:type (list :Foo)}
    :page_info {:type PageInfo}}}

sashton 2019-05-30T17:29:58.003200Z

And then we’d have the re-usable data container at least. 🤷

devth 2019-05-30T17:30:16.003400Z

yep, interesting.

sashton 2019-05-30T17:31:10.003600Z

But the details of paging over Foo’s might be different than paging over Bar’s, so it’s possible not much might be shared besides the data type

devth 2019-05-30T17:33:11.003800Z

that makes sense. i need to contemplate how this maps to the "connections" concept. e.g.:

{
  hero {
    name
    friendsConnection(first:2 after:"Y3Vyc29yMQ==") {
      totalCount
      edges {
        node {
          name
        }
        cursor
      }
      pageInfo {
        endCursor
        hasNextPage
      }
    }
  }
}

devth 2019-05-30T17:33:42.004Z

i'll probably model it directly without trying to re-use types first

sashton 2019-05-30T17:34:17.004200Z

just to complete my example, here’s the query resolver with the cursor arg:

:list_of_foos
  {:type :PagedFoo
   :args {:cursor {:type String}
          :limit {:type Int :default-value 25}}
   :resolve ....}

devth 2019-05-30T17:34:33.004400Z

thanks. that's helpful!

sashton 2019-05-30T17:35:24.004600Z

And rather than returning hasNextPage, we chose to return a null cursor at the end

✅ 1
sashton 2019-05-30T17:38:46.004900Z

Now that I look closer, I think friendsConnection might be somewhat like PagedFoo.

devth 2019-05-30T17:39:51.005100Z

yep. and maybe i could model Connection as an interface

sashton 2019-05-30T17:40:12.005300Z

friendsConnection.edges.node vs our direct foo_list

devth 2019-05-30T17:40:46.005500Z

right

orestis 2019-05-30T18:27:04.006300Z

We lifted Relay pagination and implemented a subset of it.

👍 1