Skip to main content

Code reviews rule: Use of the lightning/uiGraphQLApi module

Written by David Martin
Updated this week

Use of the lightning/uiGraphQLApi module

Why is this an issue?

The lightning/uiGraphQLApi module is being superseded by a newer lightning/graphql GraphQL API that supports more features including dynamic queries.

Examples

Example of incorrect code:

import { gql, graphql } from 'lightning/uiGraphQLApi';

export default class AccountList extends LightningElement {
@wire(graphql, {
query: gql`
query AccountQuery {
uiapi {
query {
Account(first: 10) {
edges {
node {
Name { value }
}
}
}
}
}
}
`
})
accounts;
}

Example of correct code:

import { gql, graphql } from 'lightning/graphql';

export default class AccountList extends LightningElement {
@api recordLimit = 10;

@wire(graphql, {
query: gql`
query AccountQuery($limit: Int) {
uiapi {
query {
Account(first: $limit) {
edges {
node {
Name { value }
}
}
}
}
}
}
`,
variables: '$queryVariables'
})
accounts;

get queryVariables() {
return { limit: this.recordLimit };
}
}

How can I fix violations?

  1. Update imports: Change from lightning/uiGraphQLApi to lightning/graphql.

  2. Review queries: Take advantage of new features like dynamic queries.

  3. Update variables handling: Use the new patterns for passing variables.

When should I disable this rule?

The old API is still supported, so you can disable this rule if you are not planning to upgrade.

Resources

Did this answer your question?