We can write our own custom data source by extending the base DataSource class provided by apollo-datasource, or we can use an open-source data source. They take care of challenging data-fetching logic like caching and batching, while also providing access to the GraphQL context.Ĭheck out an example of a data source in practice in the blog post, Easy and performant GraphQL over REST.
GRAPHQL PYTHON MONGODB CODE
Data sources-the topic of the rest of this article ?.Īpollo Server data sources are a collection of classes that encapsulate the code that’s specific to interacting with a particular type of data service.Join Monster fetches data from relational databases by converting GraphQL queries into SQL statements, including selecting specific fields and joining tables.Prisma, an ORM for SQL databases (and others in the future), which efficiently performs operations against databases using batching and memoization.Luckily, there are well-maintained server libraries available for a large number of programming languages like Python, Ruby, and Java (see here).īy far, the most popular language for writing a GraphQL server is JavaScript, and the most popular library is Apollo Server.įrom within our own Apollo Server instance, there are lots of different ways to source data. If we choose to code our own GraphQL server, the first thing we need to decide on is a programming language. MongoDB Stitch sources data from a linked MongoDB cluster.AppSync sources data from DynamoDB, Elasticsearch, and Aurora.Hasura sources data from Postgres databases, GraphQL services, and REST APIs.Several PaaS products provide automatically generated GraphQL APIs that fetch data from a provisioned database: Using a GraphQL PaaS (Platform-as-a-Service) Certain cloud platforms provide automatically generated GraphQL access to a particular set of data sources, and if you create your own GraphQL server, you can combine any set of data sources you like. Thanks to the flexibility of GraphQL, we have many options (back-end services, databases, external APIs, and so on). But where does a GraphQL server source that data from in the first place? GraphQL makes it easy for clients to fetch data from the server.