Discover Server
The Schema is the API
[[toc]]
Quickly prototype a GraphQL API server using different data sources. Starting a project has never been easier and fun
- Bring your own data via datasources
- Use the builtin fake data to get an API running
- Schema based relationships
Quick Start
Prototype a product API server using the builtin fakr datasource
Save this schema to a file called schema.graphql
type Product { id: ID @field(name: "random.number") name: String @field(name: "commerce.productName") price: Float @field(name: "commerce.price")}
then in the same folder run
npx discover-server
now you can fetch products
curl -H "Content-Type:application/json" -X POST \ -d '{"query": "query { find_products(limit: 2) { name price }}" }' \ http://localhost:8080/graphql
or visit http://localhost:8080/playground
to use the graphql playground IDE
add relationships by updating schema.graphql
to
type User { id: ID @field(name: "random.number") name: String @field(name: "name.findName") products: [Product]} type Product { id: ID @field(name: "random.number") name: String @field(name: "commerce.productName") price: Float @field(name: "commerce.price") user: User}
fetch owners and products
curl -H "Content-Type:application/json" -X POST \ -d '{"query": " find_users(limit: 2) {name products (where: { name: {_eq: "awesome"} }, limit: 2) { name price } }"}' \ http://localhost:8080/graphql
Datasources
- Faker (Fake data source)
- CSV
- JSON
- DynamoDB (Coming soon)
- SQLite (Coming soon)
- MySQL (Coming soon)
- Postgres (Coming soon)