How do I fetch a valid cloudflare API v4 Graphql schmea? - cloudflare

My objective is to consume the Cloudflare Graphql API, using GraphQl Code Generator.
However when I try to use the schema like this:
./src/queries-cloudflare/generated.ts:
schema:
- 'https://api.cloudflare.com/client/v4/graphql':
headers:
Authorization: Bearer <token>
documents: ./src/queries-cloudflare/queries/**/*.graphql
plugins:
- typescript
- typescript-operations
- typescript-document-nodes
I simply get an error saying Something went wrong Type mutation must define one or more fields..
What's going on here - why can't I use the schema for code generation?

The reason is that Cloudflare GraphQL API does not support mutations at the moment.
But we have plans to add it in the near future. As for now, you still can explore schema and write queries manually:
https://developers.cloudflare.com/analytics/graphql-api/getting-started/explore-graphql-schema/

Related

how to get data from backend in nuxt 3 without using composition api

I hope you are fine. I want to send a get request in nuxt3 without using composition api but I don't know how to do that. I will thank anyone who give me a piece of guidance.
Thanks.
async getPosters(){
const results = await this.$axios.get('posters')
this.posters = results.data
},
Write your code as you were used too with just Options API, nothing have changed on that matter.
You can totally use Options API while using Vue3/Nuxt3. They may have some small changes but nothing too major for a simple task of querying a backend.
It looks like this is more of an issue with trying to load Axios rather than it is with the composition API. Nuxt 3 makes Axios a redundant module.
Since Fetch is the go-to considered method of requesting data in Nuxt3, have you tried changing the method of your request? It means having to load one less module for your project, and will make it a lot easier to transition between SSR and Static in the future. If not, it might be worth using the previous version of Nuxt.
Here's the documentation: https://v3.nuxtjs.org/getting-started/data-fetching in Nuxt 3.

disable graphql queries other than crud in strapi v4

I want to create a public facing API to fetch product, category etc. using strapi v4 graphql plugin.
I can disable some crud queries in the src/index.js file using the example here.
However I don't know how to disable the queries and mutations of things that are not part of shadowCRUD such as uploadFile, uploadFolder, i18Nlocale, usersPermissions, register, login etc.
How can I achieve this in strapi v4 (v4.3.4 as of right now)
extensionService.shadowCRUD('plugin::users-permissions.role').disableQueries();
extensionService.shadowCRUD('plugin::i18n.locale').disableQueries();
extensionService.shadowCRUD('plugin::upload.folder').disableQueries();
extensionService.shadowCRUD('plugin::upload.folder').disableMutations();
extensionService.shadowCRUD('plugin::upload.file').disableMutations();
extensionService.shadowCRUD('plugin::upload.file').disableQueries();
Adding these lines did help but still some of the non-content specific mutations are there (userPermissionsUser, userPermissionsRole). Still, I think there's a much cleaner way to do this somewhere.

Can prisma achieve the same things as graphql?

I'm having a hard time understanding what graphql can achieve on top of prisma besides having a singular endpoint.
I've been hearing that the main selling point of graphql is the fact that you are able to query for the specific fields you want to receive, but can't that also be achieved with prisma using the "select" property?
const users = await user.findMany({
select: {
email: true,
},
});
Thank you for your answers!
I understand your confusion. I'll try to make the difference between Prisma and GraphQL clearer for you.
Prisma
Prisma is an ORM like tool. This means that it helps you search for data in your database. Helps you create queries, join data and etc. Prisma is a tool that lives in your back-end (usually) and helps you find the data that you will send to your front-end or mobile application.
GraphQL
GraphQL is a way to communicate with your back-end. So let's say that you want get the name of a user based on its id. On a REST API (that is the more common way) you would send a GET request to the server, and it would respond with a JSON with all of the data for this user.
// Imagine this is your request to the server
await api.get(http://myserver.com/user/1)
// Imagine this is your JSON response
{
name: "Person",
age: 24,
address: "Avenue Street, number 7",
...
}
You see that even though you just wanted the name of the user you got all of the data, when using a REST API. But with GraphQL that is not the case. You can request for only the data that you want.
// Your request to the server would look like this
{
GetUserById(1) {
name
}
}
// In the response you would be getting a JSON with only the data that you requested
{
name: "Person"
}
That is what GraphQL is used for, requesting specific data to your back-end and receiving only what you need. In both cases, REST API and GraphQL, you can use Prisma. It will help you search in your database for the data that was requested.
If you want to know more about Prisma you can check their website where you will find more about how it works and how to use it.
If you want to know more about GraphQL you can check their FAQ page
You can also learn how to use Prisma and GraphQL together

How to fix Amadeus API 500 Internal Error?

The "Flight Offers Search V2" and "Flight Offers Price V1" endpoints are returning errors. Probably it's a configuration issue
Flight Offers Search API comes with 2 different endpoints:
GET with a limited number of parameters but easier to implement for the most common use cases
POST version much more complete offering all types of filtering but it requires to build the JSON body. In that context we use a POST to offer the possibility to build the JSON body without length restriction, even if it is for a search. That's why in the swagger documentation you will find X-HTTP-Method-Override set at GET.
The Flight Offers Price API is built from the response of Flight Offers Search. To allow developers to reuse the body of the previous response we created this endpoint using the verb POST, That's why in the swagger documentation you will find X-HTTP-Method-Override set at GET.

Is it possible to get raw data from a Metabase MBQL / SQL query via the REST API?

Is there a Metabase REST API that takes a MBQL/SQL query and returns the raw data?
I can perform a MBQL query via the API in a 2-step process by doing the intermediate step of creating a Question via the Metabase web app UI and then querying the Question, but I haven't figured how how to combine MBQL with the REST API in a single step.
Some items I'd like to accomplish by having the MBQL in the API request instead of a UI-generated Question:
better version management as the MBQL query can be checked into source control with the code
better isolation as the API call won't be dependent on the question which can change
Here's some info on how to perform the 2-step process.
2-Step Process
The two step process is:
Use web app to create a MBQL/SQL Metabase Question
Use REST API to query existing Question created in web app using the Card API
Step 1) Creating Question via Web UI
Log into the web app and click the "New Question" button in the top menu.
Once your question has been created you will be directed to a URL like the following where :question-id is an integer.
Web UI endpoint: GET /question/:question-id
Note this value and use it in the API in the next step.
Note: an alternative for creating the card is to use the POST /api/card API endpoint per YakovL. This can be useful in some scenarios were UI questions/cards are desirable, but I'm also trying to avoid creating creating cards / questions in the first place, since I'm not planning on using the Metabase UI to consume them. Reasons to avoid cards for me include needing to perform extra work to verify the card query definitions haven't changed but still having the SQL in the code to create the cards, and generate a lot of unneeded question cards in the UI.
Step 2) REST API for Question Data
The API uses the term "card" for the Web UI "question" object, so make an API call to the following Card API:
API endpoint: POST /api/card/:card-id/query/:export-format
In this URL:
:card-id is the :question-id from the Web UI URL
:export-format can be json or another format
More information on the API is available in the API Documentation:
https://github.com/metabase/metabase/blob/master/docs/api-documentation.md
Question
Is there a way to do this directly by sending the MBQL/SQL query in the API request in a single step without a pre-existing Question/Card?
Querying via raw SQL and MBQL are both available via the POST /api/dataset/ API. The documentation for the endpoint mentions the query request definition but does not define it.
I ended up doing some more research and asking on the Metabase Discourse forum. The following examples were posted by sbelak.
Raw SQL Query
I was able to successfully make a native SQL query using the go-metabase SDK to make the following request:
POST /api/dataset
Content-Type: application/json
X-Metabase-Session: <sessionId>
{
"database": 1,
"native": {
"query": "SELECT COUNT(*) FROM orders"
},
type: "native"
}
Notes:
The POST /api/dataset does not set the response Content-Type header.
There is a POST /api/dataset/json endpoint, but that does not seem to accept the native property.
To set X-Metabase-Session see github.com/goauth/metabase.
MBQL
POST /api/dataset
Content-Type: application/json
X-Metabase-Session: <sessionId>
{
"database": 1,
"type": "query",
"query": {
"source-table": 2,
"breakout": [
[
"binning-strategy", ["field-id", 14], "default"
]
],
"aggregation": [["avg", ["field-id", 17]]]
}
}
Notes:
To set X-Metabase-Session see github.com/goauth/metabase.