Is @defer used in graphQL (Apollo-client 1.0.2)? I...
# prisma-whats-new
t
Is @defer used in graphQL (Apollo-client 1.0.2)? I ask as the following article implies that it does, but I'm getting an
GraphQL error: Unknown directive 'defer'. (line 8, column 39): comments(orderBy: createdAt_DESC) @defer
error message. My query is as follows:
Copy code
export const All_Posts_Comments_Query = gql`
  query allPostsCommentsQuery {
    allPostses (orderBy: createdAt_DESC) {
      __typename
      id
      displaysrc
      caption
      likes
      comments (orderBy: createdAt_DESC) @defer {
        __typename
        id
        posts {
          __typename
          id
        }
        text
        user
        deleted
      }
    }
  }
`;
https://dev-blog.apollodata.com/new-features-in-graphql-batch-defer-stream-live-and-subscribe-7585d0c28b07
n
@theom hey, @defer is currently in experimental stage and not part of the official spec yet as far as I know
t
@nilan Ok, thanks.
n
@theom may I ask what you want to use it for? I can't recall exactly what defer does 🙂
t
@nilan As stated in the article:
Copy code
This is a proposal for a new directive called defer, which is intended to minimize the time to first data. When you have a large GraphQL query for your UI, you might currently need to wait for the whole result to be generated by the server and sent over the wire to see any of it on the screen. But with defer, you can specify that some part of the query can arrive later.
So, and using my query above, when the query is initiated I would only get back all posts for initial UI rendering, followed by a subsequent 2nd server response which would then fetch all comments.
n
ah yea that's interesting - I'm not aware of neither a client or server that supports this