GraphQL: One Big Query vs Lots of Little QueriesHow to get GET (query string) variables in Express.js on Node.js?JWT Authentication: Use UI token to authenticate Graphene/Django (GraphQL) queries?How to define GraphQL input type in vue-apollo clientUpdate Apollo GraphQL cache without using refetchQueries?Should I handle a GraphQL ID as a string on the client?Graphql query erroring with 'Unknown type Int' with Apollo Client and graphql-goEncoding/validating cursor (cursor based pagination)How to solve 'TypeError: Cannot read property 'params' of undefined' with Apollo Graphql Client and React?GraphQL subscription using server-sent events & EventSourceGraphQL: Error when resolving promises during file upload
Information to fellow intern about hiring?
Need help identifying/translating a plaque in Tangier, Morocco
Is this relativistic mass?
LWC and complex parameters
Could a US political party gain complete control over the government by removing checks & balances?
Symmetry in quantum mechanics
What happens when a metallic dragon and a chromatic dragon mate?
What is the command to reset a PC without deleting any files
Ideas for 3rd eye abilities
How can I fix this gap between bookcases I made?
Are white and non-white police officers equally likely to kill black suspects?
What is the meaning of "of trouble" in the following sentence?
Why is the design of haulage companies so “special”?
Re-submission of rejected manuscript without informing co-authors
aging parents with no investments
What to wear for invited talk in Canada
Is there a name of the flying bionic bird?
Are objects structures and/or vice versa?
What do the Banks children have against barley water?
Landlord wants to switch my lease to a "Land contract" to "get back at the city"
How could a lack of term limits lead to a "dictatorship?"
Filling an area between two curves
Does the average primeness of natural numbers tend to zero?
What are the advantages and disadvantages of running one shots compared to campaigns?
GraphQL: One Big Query vs Lots of Little Queries
How to get GET (query string) variables in Express.js on Node.js?JWT Authentication: Use UI token to authenticate Graphene/Django (GraphQL) queries?How to define GraphQL input type in vue-apollo clientUpdate Apollo GraphQL cache without using refetchQueries?Should I handle a GraphQL ID as a string on the client?Graphql query erroring with 'Unknown type Int' with Apollo Client and graphql-goEncoding/validating cursor (cursor based pagination)How to solve 'TypeError: Cannot read property 'params' of undefined' with Apollo Graphql Client and React?GraphQL subscription using server-sent events & EventSourceGraphQL: Error when resolving promises during file upload
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I know this question is as old as time -- and their is no silver bullet. But I think there might be a solid pattern out there, and I would like not to invent the wheel.
Consider the following two schema options:
Approach 1) My original implementation
type Query
note(id: ID!): Note
notes(input: NotesQueryInput): [Note!]!
Approach 2) My current experimental approach
type DatedId
date: DateTime!
id: ID!
type Query
note(id: ID!): Note
notes(input: NotesQueryInput): [DatedId!]!
The differences are:
with approach 1) the notes query will either return a list of potentially large Note objects
with approach 2) the notes query will return a much lighter payload BUT then will need to execute n additional queries
So my question is with the Apollo Client / Server stack with in-memory-cache which is the best approach. to achieve a responsive client with a scalable server.
Notes
With approach 1 -- my 500mb dyno (heroku server) ran out of memory.
I expect with either approach I will implement pagination with the connection / edge pattern
the graphql server is primarly to serve my own frontend.
node.js graphql apollo apollo-client apollo-server
add a comment |
I know this question is as old as time -- and their is no silver bullet. But I think there might be a solid pattern out there, and I would like not to invent the wheel.
Consider the following two schema options:
Approach 1) My original implementation
type Query
note(id: ID!): Note
notes(input: NotesQueryInput): [Note!]!
Approach 2) My current experimental approach
type DatedId
date: DateTime!
id: ID!
type Query
note(id: ID!): Note
notes(input: NotesQueryInput): [DatedId!]!
The differences are:
with approach 1) the notes query will either return a list of potentially large Note objects
with approach 2) the notes query will return a much lighter payload BUT then will need to execute n additional queries
So my question is with the Apollo Client / Server stack with in-memory-cache which is the best approach. to achieve a responsive client with a scalable server.
Notes
With approach 1 -- my 500mb dyno (heroku server) ran out of memory.
I expect with either approach I will implement pagination with the connection / edge pattern
the graphql server is primarly to serve my own frontend.
node.js graphql apollo apollo-client apollo-server
It's a bit unclear from your question... is the assumption here that with your second approach, you are making one request, queryingnotes
, and then subsequently one request per returned id, this time requesting thenote
field?
– Daniel Rearden
Mar 22 at 2:15
Also asking for "the best approach" makes this question broad and subject to opinion. It would be helpful to provide some criteria. Is there anything other than running out of memory on your server that you're trying to address. Rather than asking "what's the best approach", can we instead ask which approach would help me achieve x, y and z?
– Daniel Rearden
Mar 22 at 2:18
@DanielRearden -- yes approach 2 requires subsequently one request per returned id. and I tried to edit the question to put more parameters on it
– Jonathan
Mar 22 at 2:32
add a comment |
I know this question is as old as time -- and their is no silver bullet. But I think there might be a solid pattern out there, and I would like not to invent the wheel.
Consider the following two schema options:
Approach 1) My original implementation
type Query
note(id: ID!): Note
notes(input: NotesQueryInput): [Note!]!
Approach 2) My current experimental approach
type DatedId
date: DateTime!
id: ID!
type Query
note(id: ID!): Note
notes(input: NotesQueryInput): [DatedId!]!
The differences are:
with approach 1) the notes query will either return a list of potentially large Note objects
with approach 2) the notes query will return a much lighter payload BUT then will need to execute n additional queries
So my question is with the Apollo Client / Server stack with in-memory-cache which is the best approach. to achieve a responsive client with a scalable server.
Notes
With approach 1 -- my 500mb dyno (heroku server) ran out of memory.
I expect with either approach I will implement pagination with the connection / edge pattern
the graphql server is primarly to serve my own frontend.
node.js graphql apollo apollo-client apollo-server
I know this question is as old as time -- and their is no silver bullet. But I think there might be a solid pattern out there, and I would like not to invent the wheel.
Consider the following two schema options:
Approach 1) My original implementation
type Query
note(id: ID!): Note
notes(input: NotesQueryInput): [Note!]!
Approach 2) My current experimental approach
type DatedId
date: DateTime!
id: ID!
type Query
note(id: ID!): Note
notes(input: NotesQueryInput): [DatedId!]!
The differences are:
with approach 1) the notes query will either return a list of potentially large Note objects
with approach 2) the notes query will return a much lighter payload BUT then will need to execute n additional queries
So my question is with the Apollo Client / Server stack with in-memory-cache which is the best approach. to achieve a responsive client with a scalable server.
Notes
With approach 1 -- my 500mb dyno (heroku server) ran out of memory.
I expect with either approach I will implement pagination with the connection / edge pattern
the graphql server is primarly to serve my own frontend.
node.js graphql apollo apollo-client apollo-server
node.js graphql apollo apollo-client apollo-server
edited Mar 22 at 2:30
Jonathan
asked Mar 22 at 1:52
JonathanJonathan
10.2k84980
10.2k84980
It's a bit unclear from your question... is the assumption here that with your second approach, you are making one request, queryingnotes
, and then subsequently one request per returned id, this time requesting thenote
field?
– Daniel Rearden
Mar 22 at 2:15
Also asking for "the best approach" makes this question broad and subject to opinion. It would be helpful to provide some criteria. Is there anything other than running out of memory on your server that you're trying to address. Rather than asking "what's the best approach", can we instead ask which approach would help me achieve x, y and z?
– Daniel Rearden
Mar 22 at 2:18
@DanielRearden -- yes approach 2 requires subsequently one request per returned id. and I tried to edit the question to put more parameters on it
– Jonathan
Mar 22 at 2:32
add a comment |
It's a bit unclear from your question... is the assumption here that with your second approach, you are making one request, queryingnotes
, and then subsequently one request per returned id, this time requesting thenote
field?
– Daniel Rearden
Mar 22 at 2:15
Also asking for "the best approach" makes this question broad and subject to opinion. It would be helpful to provide some criteria. Is there anything other than running out of memory on your server that you're trying to address. Rather than asking "what's the best approach", can we instead ask which approach would help me achieve x, y and z?
– Daniel Rearden
Mar 22 at 2:18
@DanielRearden -- yes approach 2 requires subsequently one request per returned id. and I tried to edit the question to put more parameters on it
– Jonathan
Mar 22 at 2:32
It's a bit unclear from your question... is the assumption here that with your second approach, you are making one request, querying
notes
, and then subsequently one request per returned id, this time requesting the note
field?– Daniel Rearden
Mar 22 at 2:15
It's a bit unclear from your question... is the assumption here that with your second approach, you are making one request, querying
notes
, and then subsequently one request per returned id, this time requesting the note
field?– Daniel Rearden
Mar 22 at 2:15
Also asking for "the best approach" makes this question broad and subject to opinion. It would be helpful to provide some criteria. Is there anything other than running out of memory on your server that you're trying to address. Rather than asking "what's the best approach", can we instead ask which approach would help me achieve x, y and z?
– Daniel Rearden
Mar 22 at 2:18
Also asking for "the best approach" makes this question broad and subject to opinion. It would be helpful to provide some criteria. Is there anything other than running out of memory on your server that you're trying to address. Rather than asking "what's the best approach", can we instead ask which approach would help me achieve x, y and z?
– Daniel Rearden
Mar 22 at 2:18
@DanielRearden -- yes approach 2 requires subsequently one request per returned id. and I tried to edit the question to put more parameters on it
– Jonathan
Mar 22 at 2:32
@DanielRearden -- yes approach 2 requires subsequently one request per returned id. and I tried to edit the question to put more parameters on it
– Jonathan
Mar 22 at 2:32
add a comment |
1 Answer
1
active
oldest
votes
If you're running out memory on the server, it may be time to upgrade. If you're running out of memory now, imagine what will happen when you have multiple users hitting your endpoint.
The only other way to get around that specific problem is to break up your query into several smaller queries. However, your proposed approach suffers from a couple of problems:
- You will end up hammering your server and your database with significantly more requests
- Your UI may take longer to load, depending on whether the requested data needs to be rendered immediately
- Handling the scenario when one of your requests fails, or attempting to retry a failed request, may be challenging
You already suggested added pagination, and I think it would be a much better way to break up your single large query into smaller ones. Not only does pagination lend itself to a better user experience, but by enforcing a limit on the size of the page, you can effectively enforce a limit on the size of a given query.
One other option you may consider exploring is using deferred queries. This experimental feature was added specifically with expensive queries in mind. By making one or more fields on your Note
type deferred, you would effectively return null for them initially, and their values would be sent down in a second "patch" response after they finally resolve. This works great for fields that are expensive to resolve, but may also help with fields that return a large amount of data.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291773%2fgraphql-one-big-query-vs-lots-of-little-queries%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you're running out memory on the server, it may be time to upgrade. If you're running out of memory now, imagine what will happen when you have multiple users hitting your endpoint.
The only other way to get around that specific problem is to break up your query into several smaller queries. However, your proposed approach suffers from a couple of problems:
- You will end up hammering your server and your database with significantly more requests
- Your UI may take longer to load, depending on whether the requested data needs to be rendered immediately
- Handling the scenario when one of your requests fails, or attempting to retry a failed request, may be challenging
You already suggested added pagination, and I think it would be a much better way to break up your single large query into smaller ones. Not only does pagination lend itself to a better user experience, but by enforcing a limit on the size of the page, you can effectively enforce a limit on the size of a given query.
One other option you may consider exploring is using deferred queries. This experimental feature was added specifically with expensive queries in mind. By making one or more fields on your Note
type deferred, you would effectively return null for them initially, and their values would be sent down in a second "patch" response after they finally resolve. This works great for fields that are expensive to resolve, but may also help with fields that return a large amount of data.
add a comment |
If you're running out memory on the server, it may be time to upgrade. If you're running out of memory now, imagine what will happen when you have multiple users hitting your endpoint.
The only other way to get around that specific problem is to break up your query into several smaller queries. However, your proposed approach suffers from a couple of problems:
- You will end up hammering your server and your database with significantly more requests
- Your UI may take longer to load, depending on whether the requested data needs to be rendered immediately
- Handling the scenario when one of your requests fails, or attempting to retry a failed request, may be challenging
You already suggested added pagination, and I think it would be a much better way to break up your single large query into smaller ones. Not only does pagination lend itself to a better user experience, but by enforcing a limit on the size of the page, you can effectively enforce a limit on the size of a given query.
One other option you may consider exploring is using deferred queries. This experimental feature was added specifically with expensive queries in mind. By making one or more fields on your Note
type deferred, you would effectively return null for them initially, and their values would be sent down in a second "patch" response after they finally resolve. This works great for fields that are expensive to resolve, but may also help with fields that return a large amount of data.
add a comment |
If you're running out memory on the server, it may be time to upgrade. If you're running out of memory now, imagine what will happen when you have multiple users hitting your endpoint.
The only other way to get around that specific problem is to break up your query into several smaller queries. However, your proposed approach suffers from a couple of problems:
- You will end up hammering your server and your database with significantly more requests
- Your UI may take longer to load, depending on whether the requested data needs to be rendered immediately
- Handling the scenario when one of your requests fails, or attempting to retry a failed request, may be challenging
You already suggested added pagination, and I think it would be a much better way to break up your single large query into smaller ones. Not only does pagination lend itself to a better user experience, but by enforcing a limit on the size of the page, you can effectively enforce a limit on the size of a given query.
One other option you may consider exploring is using deferred queries. This experimental feature was added specifically with expensive queries in mind. By making one or more fields on your Note
type deferred, you would effectively return null for them initially, and their values would be sent down in a second "patch" response after they finally resolve. This works great for fields that are expensive to resolve, but may also help with fields that return a large amount of data.
If you're running out memory on the server, it may be time to upgrade. If you're running out of memory now, imagine what will happen when you have multiple users hitting your endpoint.
The only other way to get around that specific problem is to break up your query into several smaller queries. However, your proposed approach suffers from a couple of problems:
- You will end up hammering your server and your database with significantly more requests
- Your UI may take longer to load, depending on whether the requested data needs to be rendered immediately
- Handling the scenario when one of your requests fails, or attempting to retry a failed request, may be challenging
You already suggested added pagination, and I think it would be a much better way to break up your single large query into smaller ones. Not only does pagination lend itself to a better user experience, but by enforcing a limit on the size of the page, you can effectively enforce a limit on the size of a given query.
One other option you may consider exploring is using deferred queries. This experimental feature was added specifically with expensive queries in mind. By making one or more fields on your Note
type deferred, you would effectively return null for them initially, and their values would be sent down in a second "patch" response after they finally resolve. This works great for fields that are expensive to resolve, but may also help with fields that return a large amount of data.
answered Mar 22 at 2:59
Daniel ReardenDaniel Rearden
17k12045
17k12045
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291773%2fgraphql-one-big-query-vs-lots-of-little-queries%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It's a bit unclear from your question... is the assumption here that with your second approach, you are making one request, querying
notes
, and then subsequently one request per returned id, this time requesting thenote
field?– Daniel Rearden
Mar 22 at 2:15
Also asking for "the best approach" makes this question broad and subject to opinion. It would be helpful to provide some criteria. Is there anything other than running out of memory on your server that you're trying to address. Rather than asking "what's the best approach", can we instead ask which approach would help me achieve x, y and z?
– Daniel Rearden
Mar 22 at 2:18
@DanielRearden -- yes approach 2 requires subsequently one request per returned id. and I tried to edit the question to put more parameters on it
– Jonathan
Mar 22 at 2:32