Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getbystatement #338

Merged
merged 5 commits into from
Oct 22, 2024
Merged

Getbystatement #338

merged 5 commits into from
Oct 22, 2024

Conversation

johngeorgewright
Copy link
Contributor

@johngeorgewright johngeorgewright commented Oct 22, 2024

The query function was always a bit of a hack to automatically type pql options based on the method you were calling.

For example, instead of:

import { GoogleAdManager, LineItemService, pql } from '@dmgt/google-ad-manager-api'

const [response] = await client.getLineItemsByStatementAsync({
  filterStatement: {
    query: pql<LineItemService.LineItems>({
      limit: 10,
      where: {
        lineItemType: 'SPONSORSHIP'
      },
    }),
  },
})

You could write something simpler, like:

import { GoogleAdManager, pql, query } from '@dmgt/google-ad-manager-api'

const [response] = await query(client, 'getLineItemsByStatementAsync', {
  limit: 10,
  where: {
    lineItemType: 'SPONSORSHIP'
  },
})

With the above you didn't need to specify the LineItemService.LineItems type for the pql function... it was automatically figured out for you by the return type of getLineItemsByStatementAsync. The only problem with this, however, is that you had to know of the function "getLineItemsByStatementAsync".

This PR adds a very similar function called "getByStatement" which doesn't require the full function name... just the item name, plus we provide the available items as a union to make things even easier.

import { getByStatement, GoogleAdManager, pql } from '@dmgt/google-ad-manager-api'

const [response] = await getByStatement(client, 'lineItems', {
  limit: 10,
  where: {
    lineItemType: 'SPONSORSHIP'
  },
})

A newer version of the `query` function that only requires a service name.
@johngeorgewright johngeorgewright marked this pull request as ready for review October 22, 2024 13:22
@johngeorgewright johngeorgewright requested a review from a team October 22, 2024 13:35
@johngeorgewright johngeorgewright merged commit 460bdfa into master Oct 22, 2024
4 checks passed
@johngeorgewright johngeorgewright deleted the getbystatement branch October 22, 2024 18:47
Copy link
Contributor

🎉 This PR is included in version 8.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant