May 17, 2023
ColdFusion 2023 – GraphQL Client
Comments
(0)
May 17, 2023
ColdFusion 2023 – GraphQL Client
ColdFusion developer for 20+ years, professional experience in 10 other languages & frameworks. Artist, nerd, Jeep enthusiast.
Newbie 35 posts
Followers: 26 people
(0)

GraphQL is a query language for APIs and a runtime for executing those queries with your existing data. It provides a more efficient, powerful, and flexible alternative to REST. In ColdFusion 2023 we are providing a native method of consuming and sending data across GraphQL using GQL. This includes support for fragments, variables, aliases, queries, mutations, subscriptions and more.

In future versions of ColdFusion we will add the ability to expose your own data as GraphQL endpoints, but in the meantime, here are a few application use case examples you might find useful in building out your own apps with GraphQL in CF2023:

GitHub API: GitHub provides a public GraphQL API that allows users to access their data like repositories, issues, pull requests, and more. It’s a powerful tool for developers who want to integrate their applications with GitHub or build tools and services that work with GitHub data.

Shopify API: Shopify uses GraphQL to provide an API for their online store platform. This API lets developers build custom storefronts, apps, and other tools that interact with Shopify. It includes endpoints for products, collections, orders, shipping, and more.

Yelp API: Yelp provides a GraphQL API that developers can use to access business reviews and ratings, search for businesses, and more. This API could be used to build an app that helps users find new restaurants, or a tool that aggregates reviews for market research.

Content Management Systems: Many modern CMSs, such as Strapi and WordPress (with the WPGraphQL plugin), provide a GraphQL API for accessing and manipulating content. This allows developers to fetch content in a highly flexible and efficient way, making it easy to build dynamic, content-driven applications. This can provide an interesting middle ground for customers with PHP based WP sites that want to integrate CF driven data source integration into their architectures.

Gatsby: Gatsby, a popular open-source framework for building websites, uses GraphQL to pull in data from various sources (like Markdown files, CMSs, APIs) at build time. This provides a highly flexible and efficient way to build static websites and web apps.

Apollo Federation: Apollo Federation is used to build a single data graph composed of multiple subgraphs, allowing different teams to work on different services independently while providing a unified API to the clients. This could be used for a large e-commerce site where different teams manage different aspects of the business, like user profiles, product catalog, orders, and more.

Hasura: Hasura auto-generates a real-time GraphQL API on top of Postgres, with webhook triggers on database events for asynchronous business logic. This can be used for building data-driven applications, real-time apps, or for augmenting existing data sources with a GraphQL layer.

Remember that GraphQL is a specification, and its use cases are broad and varied. It’s not limited to these examples and can be used wherever an API is needed that allows clients more flexibility and efficiency in working with data.

As I mentioned, you can now use GraphQL natively in your CFML. In previous versions of ColdFusion, some of the features were available via CFHTTP by passing the query through the body (and doing quite a bit of massaging to it).

Now you can use code such as the following to return data from an endpoint:

gqlClient = getGraphQLClient({
    service_name: "baseql",
    client_name : "baseql_client",
    service_url : "SERVICE_URL",
    raw_http_client: true
});
gql1 = '
    query 
        {
              table1 
             { 
                    id 
                    item 
                    notes 
                    done 
             }
}
'
response = gqlClient.fetchResponse(gql1, {});

That code will hit a service URL (which is open and read only) and return back the id, item, notes, and done columns and put that into an object called “response” which you can then iterate against.

For more details and information on the GraphQL specification, please visit the GraphQL foundation’s website here: https://graphql.org/learn/

For more information and details on the CF2023 specification of the GraphQL client, please take a look at our documentation here: https://helpx.adobe.com/coldfusion/using/graphql-coldfusion.html

 

0 Comments
Add Comment