This is part of a series about decisions my team made with our GraphQL schema. Check out that post for context, or to read about other decisions we made.
Pretty much every API needs to support an access pattern where you need to be able to query for a single user, and you also need to query for multiple users. (Replace “user” with any type of data your application models.) I played around with a few ways to handle this, and ended up putting both a singluar and a plural field of the same type at the same level of the schema. The singular field has a required primary key argument and is used to look up a specific record. The plural field returns all records of that type by default, but includes an optional argument that can be used to filter the results. Here’s an example with a User type:
Schema
Request
Response
Thanks for reading! If you're new here, I'm Sean. I spent most of my career building B2B SaaS for startups. Now I freelance, and I currently have capacity to take on one new client. If you'd like to hire me as a contractor, check out my professional experience and shoot me an email.
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.