GraphQL extract possible queries from a schema

150 Views Asked by At

I have a graphql schema that i'm parsing

type User {
  id: ID!
  name: String!
  email: String!
  age: Int
  posts: [Post!]!
}

type Post {
  id: ID!
  title: String!
  body: String!
  author: User!
  comments: [Comment!]!
}

type Comment {
  id: ID!
  body: String!
  author: User!
  post: Post!
}

type Query {
  users: [User!]!
  user(id: ID!): User
  posts: [Post!]!
  post(id: ID!): Post
  comments: [Comment!]!
  comment(id: ID!): Comment
}

i want to get extract each possible query from it as a seperate string

in the above example,

String 1

type Query {
  users: [User!]!
}

String 2

type Query {
  user(id: ID!): User
}

String 3

type Query {
  posts: [Post!]!
}

String 4

type Query {
  post(id: ID!): Post
}

String 5

type Query {
  comments: [Comment!]!
}

String 6

type Query {
  comment(id: ID!): Comment
}

what is the best way to achieve this ? i'm using graphql javascript package

0

There are 0 best solutions below