Search code examples
graphqlapollo-serverprisma-graphqlgraphql-playground

How can I add a share to GraphQL Bin option to my Apollo server playground?


I am using Apollo server to implement a GraphQL API, which automatically gives me a GraphQL Playground. According to the GraphQL Playground docs I should have (or at least be able to enable) a "Share" feature that will create a GraphQL Bin link (e.g. https://graphqlbin.com/OksD) that I could send to a colleague so they can view and run my same query.

Unfortunately this isn't available from Apollo server out of the box. How can I enable this feature? If this is not possible, is there another simple way for me to export my query from GraphQL Playground for someone else to import it? (I see the "copy curl" option, but I don't see an easy way to import from curl.)

GraphQL Bin Image


Solution

  • Add shareEnabled: true to your playground options, e.g.

            const apolloServer = new ApolloServer({
                    schema,
                    debug: isDevelopment,
                    introspection: isDevelopment,
                    playground: {
                        shareEnabled: true,    
                    },
            });
    

    You might also want to fix CORS origin headers, allowing requests from https://graphqlbin.com