Super simple schema with remote type...doesn't work

I have a super simple schema with a remote type that reaches out to the https://jsonplaceholder.typicode.com/posts REST api.

type Post @remote {
  id: Int! @id
  title: String!
  message: String! @remoteResponse(name: "body")
}

type User {
    username: String! @id
    posts: [Post!]! @custom(http: {
      url: "https://jsonplaceholder.typicode.com/posts",
      method: GET
    })
}

However, it always fails with unable to find a required field with type ID! or @id directive for @custom field posts.. Does anyone have any clues as to why?

I am pretty sure you can’t use the @id directive with a remote type. A remote type means it never gets written to the Dgraph datastore and it is only for reference. The @id directive is for the Dgraph datastore to tell the data mutation scripts to use upserts for those xid fields. It will probably work if you just remove that directive from the remote type.

So like:

type Post @remote {
  title: String!
  message: String! @remoteResponse(name: "body")
}

type User {
    username: String! @id
  	posts: [Post!]! @custom(http: {
      url: "https://jsonplaceholder.typicode.com/posts",
      method: GET
    })
}

Unfortunately, still the same error

Custom requests need to have either an ID or @id field (you can check the docs here). So you need to do something like this:

type Post @remote {
    ...
}

type User {
    ...
  	userId: String! @id
  	posts: [Post!]! @custom(http: {
      url: "https://jsonplaceholder.typicode.com/posts?userId=$userId",
      method: GET
    })
}
1 Like