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 14 2:52 PM - edited 2024 Feb 15 10:36 AM
For the bonus part:
2024 Mar 09 8:03 AM
GraphQl Query
Bonus
2024 Feb 14 3:13 PM - edited 2024 Feb 15 5:10 PM
Screenshots:
Bonus:
Thanks, @qmacro, for the additional hint. I was so close already but gave up. I tried again after seeing your hint and found the example.
2024 Feb 14 4:56 PM
2024 Feb 14 5:52 PM
I added and graphql adapter.
2024 Feb 14 10:36 PM - edited 2024 Feb 14 10:37 PM
The GraphSql plugin:
2024 Feb 15 12:59 AM - edited 2024 Feb 15 4:59 AM
Added GraphQL:
Bonus 1:
2024 Feb 15 11:52 AM
2024 Feb 15 1:46 PM
2024 Mar 09 7:47 AM
I need help on this as i am getting error
2024 Mar 09 1:05 PM
2024 Feb 15 11:53 AM
GraphQL query
Bonus - WIP
2024 Feb 16 7:45 AM
Can't seem to get the bonus execise correct. Found the server.js, but does not work 🙄
2024 Feb 16 2:15 PM
@SandipAgarwalla - if you want, direct message me on the Community Platform. I can help you with the troubleshooting or share my solution. It's only a couple of lines of code.
2024 Feb 15 12:05 PM - edited 2024 Feb 15 12:07 PM
Felt more like I was learning how to search github than understanding how it works adding the links 😕
2024 Feb 15 2:34 PM
Searching GitHub is a good skill to master! There's so much great material on CAP and everything there, that being able to pinpoint something or fish out an example of how to do something that the one that can wield search effectively has an advantage over those that can't. Plus you need to recognise and sift through CAP code examples to find the solution, so that's CAP specific! 🙂
2024 Feb 15 2:47 PM - edited 2024 Feb 15 2:47 PM
Can't argue with that and this time you guys did gave us enough tips to solve the problem 😋. In the mean time learned that how to do for the rest protocol too.
Continue keep bringing them!
2024 Feb 15 9:15 PM
I just debug the 'standard code', understand how the 'standard Cap index' page is constructed and did my own solution. Curious to find the SAP sample solution on GIT.
2024 Feb 15 1:56 PM
2024 Feb 15 2:40 PM
If I may be so bold and offer a bit of a clue to those looking to complete the bonus part of this week's task. The search facility on GitHub is fantastic, and with the help of search modifiers, you can narrow in on what you're looking for with ease.
The base search is at https://github.com/search and the query language includes parameters that allow you to specific the context of your search. For example, you might want to set the `org` to `SAP-samples` and the `type` to `code`, and perhaps the `path` to something else, while looking for the things that @thomas_jung hinted at in the bonus description 🙂
You should end up with a very specific URL that you can GET in your browser, and there are (at the time of writing) only two results, both of which have code that you can use.
Good luck!
2024 Feb 16 9:55 PM
2024 Feb 15 6:10 PM
graphql query:
bonus:
2024 Feb 15 10:34 PM
2024 Feb 16 1:20 AM
GraphQL query
Bonus 1
2024 Feb 16 11:00 AM
GraphQL
Bonus
2024 Feb 16 12:09 PM
2024 Feb 16 2:17 PM
Proxy rewrite rule? Are you trying to change the main ODataV4 URL path? If so you can do that via annotation in the service definition now since CAP 7.0. June 2023 | CAPire (cloud.sap)
2024 Feb 16 3:46 PM
2024 Feb 16 4:26 PM - edited 2024 Feb 16 5:47 PM
Hello,
Bonus :
My repo : https://github.com/meriemsouissi/dev-challenge-feb-2024
Thanks @thomas_jung for this bonus !
2024 Feb 16 7:27 PM
2024 Feb 16 10:02 PM
2024 Feb 17 2:29 PM
2024 Feb 17 10:26 PM
2024 Feb 18 1:07 PM
2024 Feb 18 6:38 PM
2024 Feb 19 6:18 AM
2024 Feb 19 6:29 AM
2024 Feb 19 7:58 AM
2024 Feb 19 9:11 AM
Hello,