본문 바로가기

개발/프론트엔드19

7. GraphQL Subscription --- # What is Subscription Subscription is used when the client wants real-time updates pushed from the server. ``` subscription liftStatusChange { name capacity status } } ``` 2019. 12. 26.
6. GraphQL Mutations # What is Mutation *Query* describes all the read actions of data. However, Mutation performs data change. Example: ``` mutation burnItDown { deleteAllData } ``` Example: ``` mutation createSong { addSong(title: "No Scrubs", numberOne: true, performerName:"TLC"){ id title numberOne } } ``` addSong() adds data in parenthesis into the database. following {} specifies which fields to retrieve if mu.. 2019. 12. 26.
5. GraphQL Interface What is an Interface An Interface is an abstract type that specifies fields that should be implemented in similar object types. When another type implements the interface, it needs to include all the fields from the interface and may add its own fields. It acts like a virtual function in C++. useful link: https://graphqlmastery.com/blog/graphql-interfaces-and-unions-how-to-design-graphql-schema 2019. 12. 26.
4. GraphQL Union If you want to return different types on different queries, you can use **union**. ``` union AgendaItem = StudyGroup | Workout ``` ``` query schedule { agneda { ...on Workout { name reps } ...on StudyGroup { name subject students } } } ``` ``` ...on Workout ``` is an inline fragment with the name "Workout" you can also use named fragments (from previous post). 2019. 12. 26.
3. GraphQL Fragments # Why do we need Fragments? Fragments are used to reduce redundancy. You can think of it as something like struct in C. For exmaple, ``` query { Lift(id: "jazz-cat") { name status capacity night elevationGain trailAccess { name difficulty } } Trail(id: "river-run"){ name difficulty accessedByLifts { name status capacity night elevationGain } } } ``` you can see that Lift wants name status capaci.. 2019. 12. 26.
2. GraphQL Query Public GraphQL APIs: SWAPI : http://graphql.org/swapi-graphql GitHub API : https://developer.github.com/v4/explorer Yelp : https://www.yelp.com/developer/graphql below examples will be run on : http://snowtooth.moonhighway.com < visit the url and type in queries You can add multiple queries to a query document but you can only run 1 query at a time. for example, # Try to write your query here qu.. 2019. 12. 26.