0

I am trying to add Relay/Global Object Identification to my GraphQL query.

My type looks like this:

[Node]
public class Speaker
{
    [ID]
    public int Id { get; set; }

    public string? Name { get; set; }

    public string? Bio { get; set; }

    public virtual string? WebSite { get; set; }

    public ICollection<SessionSpeaker> SessionSpeakers { get; set; } = new List<SessionSpeaker>();
}

My query is the following:

query {
  node(id: 1) {
    id
    ... on Speaker {
      bio
      id
      name
      webSite
    }
  }
}

I receive the following error message:

The argument literal representation is HotChocolate.Language.IntValueNode which is not compatible with the request literal type HotChocolate.Language.StringValueNode

I changed Id to be string instead of int. I receive the following error message:

query {
  node(id: "1") {
    id
    ... on Speaker {
      bio
      id
      name
      webSite
    }
  }
}
Unable to decode the id string.

According to the documentation, Relay ids do have a special format. TypeName + id in base64. When I give id like "Speaker1" -> Base 64 "U3BlYWtlcjE=" I get a different error message:

Unable to decode the id string.
query {
  node(id: "U3BlYWtlcjE=") {
    ... on Speaker {
      bio
      id
      name
      webSite
    }
  }
}

What am I doing wrong? In what kind of format should I supply the id then?

I am writing a graphql endpoint for a service, which uses int for Id. What would be the best way to do it?

4
  • "Relay ids do have a special format. TypeName + id in base64" you don't seem to have tried that with the TypeName whatever that is. Commented Jul 8, 2024 at 9:19
  • Type name is "Speaker", and id is "1". Speaker1 -> U3BlYWtlcjE=. I supplied this example above. It is not good still, and this is my issue. I can not figure it out, why does it not work. Commented Jul 8, 2024 at 9:35
  • I have no idea if that is the right format, you'd have to look at the docs, which you haven't provided. Commented Jul 8, 2024 at 9:36
  • I haven't provided the docs, because I can not provide them. The official documentation did have a backend code only without example query. I found the TypeName+id format in a different stackoverflow thread, which also did not work for me. Commented Jul 8, 2024 at 9:39

1 Answer 1

0

First write a Query that gets all Speakers. In the response of this query should be a ID field present that cotains the Relay Id generated by HotChocolate. Use that for your node interface instead of stiching it together by hand

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.