looker-open-source / sdk-codegen

One SDK to rule them all, and in the codegen bind them
MIT License
231 stars 191 forks source link

Why is "limit" a string for creating queries but a number for running them? #1512

Open nem035 opened 1 day ago

nem035 commented 1 day ago

Problem

The limit property is defined as a string for the WriteQuery type:

https://github.com/looker-open-source/sdk-codegen/blob/main/packages/sdk/src/4.0/models.ts#L13800

Which is used for creating a query:

https://github.com/looker-open-source/sdk-codegen/blob/main/packages/sdk/src/4.0/methodsInterface.ts#L6373

But limit is defined as a number for the IRequestRunQuery type:

https://github.com/looker-open-source/sdk-codegen/blob/main/packages/sdk/src/4.0/models.ts#L8583

Which is used for running a previously created query:

https://github.com/looker-open-source/sdk-codegen/blob/main/packages/sdk/src/4.0/methodsInterface.ts#L6412

Discussion

It's confusing why one needs to pass "3" when creating a query but 3 when running it.

When you create and run a query at once (i.e. run it inline):

https://github.com/looker-open-source/sdk-codegen/blob/main/packages/sdk/src/4.0/methodsInterface.ts#L6479

You also need to use a number:

https://github.com/looker-open-source/sdk-codegen/blob/main/packages/sdk/src/4.0/models.ts#L8437

Also, passing in a number when creating a query just works, despite the type being a string.

const params: Partial<IWriteQuery> = {
  model: ...,
  view: ...,
  fields: [...],
  // @ts-ignore
  limit: 3 // <--- this should be a string according to types but a number works fine
};
const query = await sdk.ok(sdk.create_query(params));
const runParams: IRequestRunQuery = {
  query_id: 1,
}
const result = await sdk.ok(sdk.run_query(runParams));

What's going on here? Why is limit a string anywhere at all?