Share on
·

Safer Code-First GraphQL Development with Inigo’s Schema Checks and Linting

Eric Murphy·

While schema-first development is a prevalent approach in GraphQL, an alternative method is gaining traction: code-first development. In this paradigm, developers craft resolver functions and data types upfront, with the GraphQL schema subsequently generated from this code. This methodology has its own set of benefits and complexities.

One notable advantage of code-first development is its familiarity with developers entrenched in coding practices. It empowers them with greater flexibility and control over the schema, allowing direct manipulation through code. Moreover, this approach fosters a nimble development process, facilitating rapid iteration and real-time feedback.

Nevertheless, code-first development has its challenges. Discrepancies between the schema and API consumers can be introduced without meticulous oversight. Moreover, documenting and communicating the schema changes to team members may require additional effort. Despite these hurdles, for teams comfortable with a code-centric approach, code-first development remains a viable strategy in GraphQL implementation.

Inigo’s arsenal of breaking change checks, schema linting, and seamless CI/CD integration elevates the safety and efficacy of building code-first GraphQL APIs. It also enhances the resilience of the development workflow by alerting developers to potential schema change issues mid-cycle. Furthermore, Inigo’s sophisticated schema versioning ensures developers stay abreast of the latest schema changes.

Code-First Breaking Change Checks

Code-first development plays to GraphQL’s strengths. GraphQL enables quick and painless API evolution with the ability to deprecate any part of the schema without breaking API consumers. Yet, developers can make mistakes, and unintentional changes can be introduced by schema generation from the code.

This is where Inigo’s breaking change checks come into play to ensure that the newest iterations will not break API consumers of the GraphQL schema derived from the latest code changes. By having Inigo track all of the latest schema changes in development and instilling breaking change checks into the developer workflow and CI/CD pipelines, breaking changes can be caught even before problematic code and schema changes are introduced.

Implementing these breaking change checks is done with the following:

  1. Adding a reference to the schema SDL to the Service or Subgraph configuration for Inigo
  2. Enabling developers to use the Inigo CLI to run inigo check
  3. Running inigo check in the CI/CD pipeline before allowing merges to happen

Code-First Schema Linting

With code-first development, every developer is empowered to make schema changes, which introduces inevitable inconsistencies in the schema for formatting and naming conventions. Inigo’s schema linting helps enforce standards for the generated schema and catch inconsistencies during development, like breaking change checks are run using inigo check.

CI/CD Integration

Whether your development model is code-first or schema-first, it’s best practice to integrate inigo check and inigo apply into your CI/CD pipelines. This prevents the merging of code and generated schema changes, which can introduce breaking changes or schema inconsistencies that can be caught by schema linting.

See it in Action with TypeGraphQL

Here is a demo application using TypeGraphQL that demonstrate a code-first approach to building a GraphQL service. In the README there are instructions on how to make a code change that creates a breaking change, depending on client usage of the API’s schema.

Conclusion

In summary, Inigo's suite of tools for code-first GraphQL development brings a new level of robustness and reliability to teams opting for this approach. Integrating breaking change checks, schema linting, and comprehensive CI/CD pipeline tools, Inigo significantly mitigates the risks of rapid API evolution inherent in code-first projects. This allows development teams to focus more on innovation and less on the potential pitfalls of schema inconsistencies or breaking changes.

Ultimately, Inigo empowers developers to leverage the complete flexibility and power of GraphQL, maintaining high standards of quality and consistency in their API development processes. With such tools, teams can confidently navigate the complexities of code-first GraphQL development, ensuring that their APIs remain robust, consistent, and forward-compatible.

Ready to take the next steps with Inigo? You can:

  1. Get started for free at app.inigo.io
  2. Book a demo today at inigo.io/demo
  3. Ask questions on our Slack channel
Ready to accelerate your GraphQL adoption?
Start Inigo for free
*No credit card needed
Join our newsletter