vektah / gqlparser

A port of the parser from graphql-js into golang
MIT License
498 stars 123 forks source link

Can I use this library to generate a graphql response payload? #252

Open zhaoyi0113 opened 1 year ago

zhaoyi0113 commented 1 year ago

Thanks for releasing this awesome library. I am looking for a way to generate graphql response payload from raw data. What am doing is to take raw data from database and publish this data to subscribers via graphql subscription websocket. I have a schema like:

type Message {
  msg: String!
  id: ID!
  topic: String!
}

type Mutation {
  sendChat(topic: String!, message: String!): ID!
}

type Query {
  getChat(id: ID!): String!
}

type Subscription {
  # Subscribe to events on the given topic.
  event(
    # Name of the topic to subscribe to.
    on: String!
  ): Message!
}

when there is a need to publish Message data to subscribers, I will need to convert the raw data: { event: { msg: 'hello', topic: 'xxxx' } } to a payload the Apollo client expects.

Is there a way I can do that by using this library? The payload needs to include the __typename as well.