2024 Feb 14 12:57 PM - edited 2024 Mar 05 4:13 PM
If you missed week 1, you can find all the details: here
Now that the challenge is complete: here is my sample solution: jung-thomas/dev-challenge-feb-2024: Developer Challenge February 2024 (github.com)
This week's challenge is going to build upon what we learned last week with the OData V2 plugin. We will continue working with the same project, but now we want to add support for GraphQL.
GraphQL is a query language for APIs and a runtime for executing those queries by using a type system you define for your data. Unlike REST, which uses multiple URLs to access different resources, GraphQL accesses all the resources from a single endpoint with queries that articulate exactly what data is needed.
GraphQL and OData are both specifications for building and consuming APIs but take different approaches to some aspects.
GraphQL is a query language for APIs and a runtime for executing those queries by using a type system you define for your data.
OData defines a set of best practices for building and consuming RESTful APIs. It extends REST by providing a uniform way to describe both the data and the data model, enabling more detailed queries and interactions with the data.
The SAP Cloud Application Programming model was designed to be protocol agnostic as much as possible. While OData V4 is the default service type exposed by CAP applications; CAP was never intended to only support OData or just one version of that specification. Therefore its possible from a single model and service definition to support both OData and GraphQL even with the differences in approaches used by the two different protocols!
Use the GraphQl Adapter plug-in to add GraphQL support to your project and to ONLY the CatalogService endpoint. And make sure that this same service also still supports OData V4 in parallel.
GraphQL Adapter: The GraphQL Adapter is a protocol adapter that generically generates a GraphQL schema for the models of an application and serves an endpoint that allows you to query your services using the GraphQL query language.
https://github.com/cap-js/graphql
To complete the challenge, post a screenshot from the graphql test tool (which can be accessed from /graphql url of your application) running a query against the ListOfBooks entity in the CatalogService.
Bonus 1: The test tool doesn't automatically include a link to the GraphQL test tool. But using a server.js file we can use the on serving event to extend the CAP test tool ourselves. Your bonus challenge is to add the code to your project to expose a link in the test tool to the GraphQL page but only for the service endpoints that support GraphQL. Hint: Several of the samples in the SAP-Samples repository on GitHub perform this technique.
2024 Feb 19 12:14 PM
2024 Feb 19 5:59 PM
2024 Feb 19 6:51 PM - edited 2024 Feb 19 7:04 PM
Graph QL Query
Bonus part
2024 Feb 19 9:27 PM
2024 Feb 20 5:48 AM
I am still working on the bonus part
2024 Feb 22 9:30 PM
2024 Feb 23 6:14 AM
2024 Feb 26 5:24 PM
@thomas_jung this was fun, thanks. At some point I would like to see how people solved the bonus challenge. I tried 2 ways, both created the expected outcome, but the second was more generic.
2024 Feb 23 7:17 AM - edited 2024 Feb 23 7:19 AM
2024 Feb 23 3:23 PM
2024 Feb 25 5:35 PM
2024 Feb 26 7:23 AM
2024 Feb 27 6:18 AM - edited 2024 Feb 27 6:28 AM
Task Result:
Bonus :
Query : I have used service.definition["@graphql"] to check whether it supports GraphQL.
However not sure how to generate it as the first end point
2024 Feb 29 12:02 PM
Bonus 1 :
Found the solution after long search, but still not able to remove extra links and arrange the order
2024 Mar 01 8:48 AM
2024 Mar 02 8:52 AM
2024 Mar 04 12:36 PM
2024 Mar 04 12:42 PM