graphQL - sarahduv-401-advanced-javascript/seattle-javascript-401d32 GitHub Wiki
graphQL
What is graphQL?
- GraphQL is a data query language and specification developed internally by Facebook in 2012 before being publicly open sourced in 2015. It provides an alternative to REST-based architectures with the purpose of increasing developer productivity and minimizing amounts of data transferred. GraphQL is used in production by hundreds of organizations of all sizes including Facebook, Credit Karma, GitHub, Intuit, PayPal, the New York Times and many more.
GraphQL
- This is an alternative to REST:
- While REST has a huge list of endpoints and methods, GraphQL says:
- Let's just use one endpoint and one method, and let the user specifiy exactly what they want.
- i.e. --> it may have a ton a data, but you only want a specific subset of data.
- GraphQL functions by letting developers specify a Schema, which has a list of queries that can be performed on data and their respective resolvers:
- Resolver --> whatever operations are needed to fulfill a query.
- While REST has a huge list of endpoints and methods, GraphQL says:
type Query{
people: [peopleTypes]
}
{
people: () => people.find();
}
Mongoose Virtuals
- categories.virtual
- A virtual lets us populate a virtual field that doesn't formally exist on our schema.
- We can combine lifecycle hooks to take fields that match on seperate models (the instance of the schema) and associate them. This would be the equivalent of a join in SQL.
Sources: https://foundation.graphql.org/