Giter VIP home page Giter VIP logo

dataloader-codegen's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar gydbd avatar kkellyy avatar magicmark avatar quantsini avatar ryanruanwork avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dataloader-codegen's Issues

Non-required param as batchKey for batch resources would cause flow type check errors.

Currently when a batch resource is configured, if the batchKey for the underlying endpoint is not a required param, there will be flow type check errors raised.

Issue sample with details


For an endpoint like:

    TestUserApi:
        getUsers:
            isBatchResource: true
            docsLink: http://hostname/?service=testservice#/testuserapi/get_users
            batchKey: user_ids
            newKey: user_id
            reorderResultsByKey: id

where the user_ids param is non-required, the generated clientlib would look like:

getUsers($ReadOnly<{| user_ids?: $ReadOnlyArray<number>, user_emails?: $ReadOnlyArray<string>, |}>, options?: RequestOptions): Promise<Array<User>>,

in the lib/api.js.flow file. Note for user_ids it looks like: user_ids?: $ReadOnlyArray<number>.

At runtime, everything works as expected, as long as the user_ids is supplied properly.

But when doing flow type validation, it will cause below error:

Cannot instantiate `$ElementType` because an index signature declaring the expected key / value type is missing in
undefined [1].

                        v------------
               user_id: $ElementType<
                 $PropertyType<
                   $Call<
                     ExtractArg,
                     [
                       $PropertyType<
                         $PropertyType<ResourcesType, "TestUserApi">,
                         "getUsers"
                       >
                     ]
                   >,
                   "user_ids"
                 >,
                 0
               >
                ^
References:
   node_modules/@test-clientlib/testapi/lib/api.js.flow:
        getUsers($ReadOnly<{| user_ids?: $ReadOnlyArray<number>, user_emails?: $ReadOnlyArray<string>,  |}>, options?: RequestOptions): Promise<Array<User>>,
                                         ^^^^^^^^^^^^^^^^^^^^^ [1]

Support specifying headers per-request

In Yelp/bravado, developers can specify per-request configuration by passing in _request_options to the service call. A potential usecase is specifying headers which are consumed by the downstream service (or services in the middle of the request path), such as Yelp/casper.

The python api looks like:

client = SwaggerClient.from_url(...)
request_options = { ... }
client.pet.getPetById(petId=42, _request_options=request_options).response().result

A potential solution is to expose a similarly named parameter in the JS equivalents.

Feature: Add support for multiple batch keys

This feature request is to support endpoints with multiple batch ids.

Example use case

The endpoint that would benefit from this would be an endpoint that takes multiple batch ids and returns a nested object, such as an endpoint with the following definition:

Endpoint request
business_ids: str[]
features: str[]

Endpoint response

{
  "businessId1": {
    "feature1": "yes",
    "feature2": "no"
  },
  "businessId2": {
    "feature1": "yes"
  }
}

With the current dataloaders functionality, we would be able to set:

batchKey: business_ids
newKey: business_id

which would group multiple requests for that single feature for different businesses, but not multiple requests for different features on the same business. Where there is a large number of features, this could get expensive pretty quickly.

Proposed New Functionality

The ability to set multiple (or at least a secondary level of) batch keys, and then where right now we get back response[business_id] from the dataloader, we would get back something like response[business_id][feature] as the value at that feature for that business.

batchKey: business_ids
newKey: business_id
secondaryBatchKey: features
secondaryNewKey: feature

Add option to toggle if callsite should include all underlying resource parameters

Right now, we assume that resources look something like this:

function getFoo({ count, type, somethingElse }, fetch, options) {
  ...

i.e. we assume that the underlying resource takes its actual data arguments in the first parameter as an object. The rest are meta arguments which have defaults, and we never really care about overriding them from inside a resolver method.

In this world, a dataloader interface would look like this:

getFoo.load({ count: 4, type: 'baz', somethingElse: 'qux' });

This fits nicely with the interface of dataloader anyway (you can only send one argument as a key)

This assumption has been made because that's the interface of the underlying resources Yelp currently uses. But this might not always be true!

Proposed New Functionality

We should add an option - something like "useAllArguments" so if you wanted to override fetch from a resolver method, your dataloader interface would look like this:

getFoo.load([{ count: 4, type: 'baz', somethingElse: 'qux' }, myCustomFetch]);

What's the workaround in the meantime

You can use resource middleware to transform the thing that actually gets send to the underlying resource for now, to add extra arguments

Support endpoints where items are nested by ID

e.g. an endpoint might be the following shape:

GET /widgets?ids=1,2,3,6,8

returns

{
	"1": {
		"widgetName": "foo"
	},
	"2": {
		"widgetName": "bar"
	},
	"5": {
		"widgetName": "baz"
	},
	"8": {
		"widgetName": "qux"
	}
}

We currently don't support this as a batch endpoint - we've seen this in the wild, and should support it :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.