check-apollo-provider

Try in Playground
apollo-graphql-client-javascriptBest PracticeInformational

0

No tags

No CWE or CVE

The ApolloProvider used in react must have a client attribute that has the Apollo client to use with React.

Ast Rule: html element


check-apollo-provider

How to write a rule
function visit(node, filename, code) {
  if (node.tag && node.tag.value === "ApolloProvider") {
    const hasClient = node.attributes.filter(a => a.name && a.name.value && a.name.value === "client").length > 0;
    if (!hasClient) {
      const error = buildError(node.tag.start.line, node.tag.start.col,
        node.tag.end.line, node.tag.end.col,
        "must provide a client attribute", "WARNING", "BEST_PRACTICE");
      addError(error);
    }
  }
}

without-client.js

Expected test result: has error

root.render(
  <ApolloProvider>
    <App />
  </ApolloProvider>,
);

with-client.js

Expected test result: no error

root.render(
  <ApolloProvider client={client}>
    <App />
  </ApolloProvider>,
);
Add comment

Log in to add a comment


    Be the first one to leave a comment!

Codiga Logo
Codiga Hub
  • Rulesets
  • Playground
  • Snippets
  • Cookbooks
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.