|
| 1 | +# SOME DESCRIPTIVE TITLE. |
| 2 | +# Copyright (C) 2017, Brad Baker |
| 3 | +# This file is distributed under the same license as the graphql-java |
| 4 | +# package. |
| 5 | +# FIRST AUTHOR <EMAIL@ADDRESS>, 2017. |
| 6 | +# |
| 7 | +#, fuzzy |
| 8 | +msgid "" |
| 9 | +msgstr "" |
| 10 | +"Project-Id-Version: graphql-java current\n" |
| 11 | +"Report-Msgid-Bugs-To: \n" |
| 12 | +"POT-Creation-Date: 2017-11-14 18:16+0800\n" |
| 13 | +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
| 14 | +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
| 15 | +"Language-Team: LANGUAGE <LL@li.org>\n" |
| 16 | +"MIME-Version: 1.0\n" |
| 17 | +"Content-Type: text/plain; charset=utf-8\n" |
| 18 | +"Content-Transfer-Encoding: 8bit\n" |
| 19 | +"Generated-By: Babel 2.5.1\n" |
| 20 | + |
| 21 | +#: ../../batching.rst:2 |
| 22 | +msgid "Using Dataloader" |
| 23 | +msgstr "" |
| 24 | + |
| 25 | +#: ../../batching.rst:4 |
| 26 | +msgid "" |
| 27 | +"If you are using ``graphql``, you are likely to making queries on a graph" |
| 28 | +" of data (surprise surprise). But its easy to implement inefficient code" |
| 29 | +" with naive loading of a graph of data." |
| 30 | +msgstr "" |
| 31 | + |
| 32 | +#: ../../batching.rst:7 |
| 33 | +msgid "" |
| 34 | +"Using ``java-dataloader`` will help you to make this a more efficient " |
| 35 | +"process by both caching and batching requests for that graph of data " |
| 36 | +"items. If ``dataloader`` has seen a data item before, it will have " |
| 37 | +"cached the value and will return it without having to ask for it again." |
| 38 | +msgstr "" |
| 39 | + |
| 40 | +#: ../../batching.rst:10 |
| 41 | +msgid "" |
| 42 | +"Imagine we have the StarWars query outlined below. It asks us to find a " |
| 43 | +"hero and their friend's names and their friend's friend's names. It is " |
| 44 | +"likely that many of these people will be friends in common." |
| 45 | +msgstr "" |
| 46 | + |
| 47 | +#: ../../batching.rst:28 |
| 48 | +msgid "" |
| 49 | +"The result of this query is displayed below. You can see that Han, Leia, " |
| 50 | +"Luke and R2-D2 are a tight knit bunch of friends and share many friends " |
| 51 | +"in common." |
| 52 | +msgstr "" |
| 53 | + |
| 54 | +#: ../../batching.rst:42 |
| 55 | +msgid "" |
| 56 | +"A naive implementation would called a `DataFetcher` to retrieved a person" |
| 57 | +" object every time it was invoked." |
| 58 | +msgstr "" |
| 59 | + |
| 60 | +#: ../../batching.rst:44 |
| 61 | +msgid "" |
| 62 | +"In this case it would be *15* calls over the network. Even though the " |
| 63 | +"group of people have a lot of common friends. With `dataloader` you can " |
| 64 | +"make the `graphql` query much more efficient." |
| 65 | +msgstr "" |
| 66 | + |
| 67 | +#: ../../batching.rst:47 |
| 68 | +msgid "" |
| 69 | +"As `graphql` descends each level of the query ( eg as it processes `hero`" |
| 70 | +" and then `friends` and then for each their `friends`), the data loader " |
| 71 | +"is called to \"promise\" to deliver a person object. At each level " |
| 72 | +"`dataloader.dispatch()` will be called to fire off the batch requests for" |
| 73 | +" that part of the query. With caching turned on (the default) then any " |
| 74 | +"previously returned person will be returned as is for no cost." |
| 75 | +msgstr "" |
| 76 | + |
| 77 | +#: ../../batching.rst:52 |
| 78 | +msgid "" |
| 79 | +"In the above example there are only *5* unique people mentioned but with " |
| 80 | +"caching and batching retrieval in place their will be only *3* calls to " |
| 81 | +"the batch loader function. *3* calls over the network or to a database " |
| 82 | +"is much better than *15* calls you will agree." |
| 83 | +msgstr "" |
| 84 | + |
| 85 | +#: ../../batching.rst:55 |
| 86 | +msgid "" |
| 87 | +"If you use capabilities like " |
| 88 | +"`java.util.concurrent.CompletableFuture.supplyAsync()` then you can make " |
| 89 | +"it even more efficient by making the the remote calls asynchronous to the" |
| 90 | +" rest of the query. This will make it even more timely since multiple " |
| 91 | +"calls can happen at once if need be." |
| 92 | +msgstr "" |
| 93 | + |
| 94 | +#: ../../batching.rst:59 |
| 95 | +msgid "Here is how you might put this in place:" |
| 96 | +msgstr "" |
| 97 | + |
| 98 | +#: ../../batching.rst:121 |
| 99 | +msgid "```" |
| 100 | +msgstr "" |
| 101 | + |
| 102 | +#: ../../batching.rst:123 |
| 103 | +msgid "" |
| 104 | +"One thing to note is the above only works if you use " |
| 105 | +"`DataLoaderDispatcherInstrumentation` which makes sure " |
| 106 | +"`dataLoader.dispatch()` is called. If this was not in place, then all " |
| 107 | +"the promises to data will never be dispatched ot the batch loader " |
| 108 | +"function and hence nothing would ever resolve." |
| 109 | +msgstr "" |
| 110 | + |
| 111 | +#: ../../batching.rst:128 |
| 112 | +msgid "Per Request Data Loaders" |
| 113 | +msgstr "" |
| 114 | + |
| 115 | +#: ../../batching.rst:130 |
| 116 | +msgid "" |
| 117 | +"If you are serving web requests then the data can be specific to the user" |
| 118 | +" requesting it. If you have user specific data then you will not want to " |
| 119 | +"cache data meant for user A to then later give it to user B in a " |
| 120 | +"subsequent request." |
| 121 | +msgstr "" |
| 122 | + |
| 123 | +#: ../../batching.rst:133 |
| 124 | +msgid "" |
| 125 | +"The scope of your DataLoader instances is important. You might want to " |
| 126 | +"create them per web request to ensure data is only cached within that web" |
| 127 | +" request and no more." |
| 128 | +msgstr "" |
| 129 | + |
| 130 | +#: ../../batching.rst:136 |
| 131 | +msgid "" |
| 132 | +"If your data can be shared across web requests then you might want to " |
| 133 | +"scope your data loaders so they survive longer than the web request say." |
| 134 | +msgstr "" |
| 135 | + |
| 136 | +#: ../../batching.rst:139 |
| 137 | +msgid "" |
| 138 | +"But if you are doing per request data loaders then creating a new set of " |
| 139 | +"``GraphQL`` and ``DataLoader`` objects per request is super cheap. Its " |
| 140 | +"the ``GraphQLSchema`` creation that can be expensive, especially if you " |
| 141 | +"are using graphql SDL parsing." |
| 142 | +msgstr "" |
| 143 | + |
| 144 | +#: ../../batching.rst:142 |
| 145 | +msgid "" |
| 146 | +"Structure your code so that the schema is statically held, perhaps in a " |
| 147 | +"static variable or in a singleton IoC component but build out a new " |
| 148 | +"``GraphQL`` set of objects on each request." |
| 149 | +msgstr "" |
| 150 | + |
| 151 | +#~ msgid "" |
| 152 | +#~ "But if you are doing per request" |
| 153 | +#~ " data loaders then creating a new " |
| 154 | +#~ "set of ``GraphQL`` and ``DataLoader`` " |
| 155 | +#~ "objects per request is super cheap. " |
| 156 | +#~ "Its the ``GraphQLSchema`` creation that " |
| 157 | +#~ "can be expensive, especially if you " |
| 158 | +#~ "are using graphql IDL parsing." |
| 159 | +#~ msgstr "" |
| 160 | + |
0 commit comments