Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to pass a fragment to graphiql?

It's possible to pass a query, but apparently not a fragment:

server.use('/graphiql', graphiqlExpress({
    endpointURL: '/graphql',
    query: `# Welcome to GraphiQL

query PostsForAuthor {
  author(id: 1) {
    firstName
    posts {
      title
      votes
    }
  }
}`}));


Update 10/12/2017 It is possible to send fragments along with a query using Apollo's client:

http://dev.apollodata.com/core/fragments.html

This is not a solution to the original question, however; I would like to pass fragments to a graphiql server instance at startup.

like image 359
Jeff Lowery Avatar asked Nov 07 '22 18:11

Jeff Lowery


1 Answers

by startup do you mean from the server? if so I don't believe that's how fragments are used. my understanding is as follows:

  1. on the server you provide Types (like User)
  2. on the client you query those Types using queries and fragments

for instance, if you provide type User on the server, on the client graphQL you can use fragments to query that type:

graphQL (client)

fragment authorData on AuthorType{
  firstName
  posts {
    title
    votes
  }
}

query PostsForAuthor {
  author(id: 1) {
    ...authorData
  }
}
like image 88
galki Avatar answered Nov 30 '22 22:11

galki