Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions from workshop 1 #2

Open
derekngo opened this issue May 1, 2020 · 2 comments
Open

Questions from workshop 1 #2

derekngo opened this issue May 1, 2020 · 2 comments

Comments

@derekngo
Copy link

derekngo commented May 1, 2020

  1. How is root typed in Typescript? (In the resolver map)
  2. Does every object that gets passed back to the client essentially get JSON parsed since it has to resolve every field of every object? Have you seen any performance issues with this in production/scale?
@DerekCuevas
Copy link
Owner

DerekCuevas commented May 4, 2020

1

This doc does a good job explaining/breaking down the resolver map https://www.apollographql.com/docs/graphql-tools/resolvers/#resolver-function-signature. What it names obj we named root.

The rule for the type of root is pretty simple, root is just the parent type of the field.

For example, the name resolver for the below type would have the signature: name: (root: Foo): string, because name is defined within Foo.

type Foo {
  id: ID!
  name: String!
}

https://graphql-code-generator.com is able to generate the correct type for root for every field in our schema based on what is defined by us in the SDL.

The generated types aren't the most strait forward to read through, but looking at the definition for Resolvers may help show this (https://github.com/DerekCuevas/workshop/blob/master/backend/src/index.ts#L3)

@DerekCuevas
Copy link
Owner

DerekCuevas commented May 4, 2020

2

I'm not quite sure I fully understand this question. Specifically, i'm uncertain about what you mean by "since it has to resolve every field of every object". But, will try to answer, let me know if this gets at what you were wondering about.

When resolving a GraphQL query, on the server, only the field resolvers for fields specified in the query will be executed. Similarly, only data for those fields will be encoded and sent to the client.

A benefit of this, when compared to a traditional REST endpoint, would be that clients can specific only the fields they need to use. This helps clients minimize the size of the corresponding response. So if anything, I would say that GraphQL is more optimal in this regard when compared to REST.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants