You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: add lazy GraphQL fields
This commit introduces lazy fetching of GraphQL fields. Now, the
`GraphQLFragmentMixin.get_fragments()` method has a new `lazy` argument,
which will make it skip certain fields that are considered "large".
A field is lazy-loadable when:
1. It is a `List`, `Union` or `Optional` of `GraphQLFragmentMixin`.
2. It is not marked as `NOT_LAZY`.
This will make a difference when fetching things like metrics. In
"eager" mode, the client will fetch all subfields of each metrics,
including dimensions and entities, which makes the response potentially
very large. Now, if the client is "lazy", the `.metrics()` method will
only return the metrics themselves, and the `dimensions` and `entities`
fields will be empty.
Certain things like saved query exports don't need lazy fields as their
child objects are not large, so it's worth it to just fetch everything
in one go.
I added two tests for this functionality. One is to make sure that the
`get_fragments()` method returns the expected GraphQL fragments for lazy
fields. The other is to ensure that all lazy-loadable fields have a
default value which can be used to initialize the property locally when
it's not initialized from server data.
In the next commit, I'll wire this through the client to make it
actually work in the APIs.
* feat: added `_client` to all GraphQL models
This commit adds a private `_client` property to all
`GraphQLFragmentMixin` which will get auto-populated by the loading
client. This is so that methods such as `Metric.load_dimensions()` will
be able to refer back to the client to make requests.
* feat: added `SyncMetric` and `AsyncMetric`
This is for type checking
* docs: changie
* docs: add example for lazy loading
* docs: add lazy loading to README
* fix: small error in README and `_attach_self_to_parsed_response`
* test: remove useless test
By default, the SDK will eagerly request for lists of nested objects. For example, in the list of `Metric` returned by `client.metrics()`, each metric will contain the list of its dimensions, entities and measures. This is convenient in most cases, but can make your returned data really large in case your project is really large, which can slow things down.
98
+
99
+
It is possible to set the client to `lazy=True`, which will make it skip populating nested object lists unless you explicitly load ask for it on a per-model basis. Check our [lazy loading example](./examples/list_metrics_lazy_sync.py) to learn more.
100
+
95
101
### More examples
96
102
97
103
Check out our [usage examples](./examples/) to learn more.
0 commit comments