Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

February Developer Challenge - CAP Plugins: Week 2

thomas_jung
Developer Advocate
Developer Advocate

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.

What is 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.

How does this impact the SAP Cloud Application Programming Model?

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!

Your Task this week

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. 

graphql1.png

 

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.
graphql2.png

57 REPLIES 57

Nagarajan-K
Explorer

ajos
Explorer

johna69
Product and Topic Expert
Product and Topic Expert

johna69
Product and Topic Expert
Product and Topic Expert

@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.

SRINIVAS_KATTA
Explorer

Hello @thomas_jung ,

 

SRINIVAS_KATTA_0-1708672662700.png

But not showing Graphical in catalog service..

SRINIVAS_KATTA_1-1708672770857.png

 

Thank you...

RafkeMagic
Active Contributor

RafkeMagic_0-1708701813159.png

will check the bonus one this weekend (gotta run now)

BrijeshGandhi
Explorer

Task Result:

BrijeshGandhi_0-1709011326900.png

Bonus :

BrijeshGandhi_0-1709015214337.png

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

RameshShrestha
Contributor

RameshShrestha_0-1709207995793.png

 

Bonus 1 :

Found the solution after long search, but still not able to remove extra links and arrange the order

RameshShrestha_1-1709208090072.png

 

 

spassaro
Participant

sabarna17
Contributor

want to revisit for bonus, but for now - 

sabarna17_0-1709369548809.png