An alias allows you to query similar fields while avoiding argument conflicts. In this video, Eve shares how to query like fields using aliases for the repository field.
- [Narrator] In a previous video…we queried the repository field.…This time I'd like to get the data…for the graph QL repo,…but I also want to query some data…from the react repo.…Now both of these are projects…that were created at Facebook,…so the owner argument value will be Facebook for both.…It might be tempting to do something like this,…to copy and paste the repository query…and just to swap out graphQL for react.…As soon as I hit play on this though…we're going to see an error.…
There's an argument conflict because we've made a request…for the same field with two different arguments.…So to solve this, I can use an alias.…Aliases allow us to give the field a customized name…and to request data from the same fields…with different arguments.…So here on Line 2,…I'm going to call this alias graphqlProject.…And then we'll use a colon and add a little space there.…The next thing I'm going to do here on Line 7…is create an additional alias for our reactProject.…
Awesome.…So as soon as I hit play on this we're going to see…
In this course, learn how to get started with GraphQL. Eve Porcello walks through the basics of this query language, diving into the data fetching specification, and helping you get up to speed with the syntax and vocabulary of GraphQL. Eve explains how to create basic queries, including how to work with arguments and multiple fields. She also goes into complex techniques for handling data, including working with aliases, fragments, and pagination. Plus, she covers how to edit and transform data with mutations.
- Learning about the origins of GraphQL
- Learning about how GraphQL makes data fetching and updating easier
- Creating basic queries
- Using multiple fields
- Understanding schemas
- Handling data
- Drilling down into nested fields with a query
- Adding variables for argument values
- Creating mutations
- Adding a reaction mutation