graphql / graphql-playground

🎮 GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration)
MIT License
8.77k stars 735 forks source link

Use local schema #650

Open acoreyj opened 6 years ago

acoreyj commented 6 years ago

This issue pertains to the following package(s):

Can you use a local schema instead of an endpoint or do you need a server? For instance using https://www.npmjs.com/package/apollo-link-schema instead of a server endpoint?

acoreyj commented 6 years ago

Anyone have any thoughts on if this is easily possible?

danielkcz commented 6 years ago

@acoreyj I assume you mean to use the playground as a docs browser only? Otherwise, you some logic to actually execute queries/mutations and GraphQL is not that magical to figure that out based on the schema only. There is a .graphqlconfig which playground supports and in theory, it might be possible to create an extension that would mock responses, but honestly I don't see much of use for such case.

acoreyj commented 6 years ago

@FredyC

Yea likely it would mainly be used for docs browsing or debugging/mocking in a more shareable way than the apollo debugging chrome extension.

I noticed that playground uses apollo-link-http so thought it may be simple to use a different apollo link such as apollo-link-state or apollo-link-schema

This would allow executable and mocked schemas created with graphql-tools to be used with playground

danielkcz commented 6 years ago

I see. Using apollo-link-schema along with addMockFunctionsToSchema might indeed solve that. Why don't you give it a go and make a PR? :)

Personally, I would not be using that. Creating simple mock server is super easy and added benefit is I am able to customize the mocks so it does not return "Hello" string everywhere :)

0xR commented 5 years ago

Another interesting usecase: A graphql schema that proxies to REST calls can run in the browser with real data instead of mock data. I'm a developer on https://github.com/yarax/swagger-to-graphql/ and I'd like to use graphql-playground to try out swagger-to-graphql in the browser. But since local schemas are not supported I'm going to try graphiql first.