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;








1















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.










share|improve this question
























  • 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











  • @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

















1















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.










share|improve this question
























  • 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











  • @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













1












1








1








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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, 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











  • @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











  • 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












1 Answer
1






active

oldest

votes


















2














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.






share|improve this answer























    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
    );



    );













    draft saved

    draft discarded


















    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









    2














    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.






    share|improve this answer



























      2














      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.






      share|improve this answer

























        2












        2








        2







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 2:59









        Daniel ReardenDaniel Rearden

        17k12045




        17k12045





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현