How can I create a query on the FaunaDb cli? - graphql

I am trying to create a query on the Fauna DB command line interface.
I have a collection and if I run
Map(Paginate(Documents(Collection('users'))), Lambda(x => Get(x)))
I get
data: [
{
ref: Ref(Collection("users"), "350926483869401600"),
ts: 1670928424920000,
data: {
username: 'jeff',
login_id: '123621b8-d6fc-465e-90ae-dca8d83e3321'
}
}
]
This page suggests that I can write a query thus
{users{username}}
But when I attempt it the cli hangs on the ... prompt
If I try
{
users
{
username
}
}
it returns
Uncaught ReferenceError: users is not defined
What am I doing wrong?

The page you link to is the general documentation for GraphQL, which is independent of Fauna.
The Fauna CLI is not a GraphQL client. The shell command lets you query your databases with FQL. The online shell in the customer Dashboard is the same. Both the CLI shell and online shell use the Javascript FQL drivers, so the shell is treating your input like javascript and throwing an error because there is no users variable.
To use GraphQL with Fauna, you must first upload a GraphQL schema through the Dashboard (Check out our GraphQL quick-start tutorial), or using the CLI upload-graphql-schema command, or even directly with an HTTP request.
Once you have uploaded a GraphQL schema, Fauna will host a GraphQL API that you can query through the playground in the Dashboard, or use your preferred GraphQL client.

Related

Export / finding GraphQL Schema with Strapi and GraphQL plugin

I’m new to Strapi and to GraphQL.
I successfully created a website that uses Apollo to query data from my Strapi website.
So functionally I have everything I need.
For my DX I’m wondering:
Since I installed the GraphQL IntelliJ plugin: Where do I find the schemas for it? I read something about remote schema detection - is that supported with Strapi GraphQL Plugin? Where can I read about it? Otherwise how can I export GraphQL schema files from Strapi?
If I got 1) to work: Will TypeScript types work out of the box? Would I use one of the GraphQL schema to TS converters out there? It feels like there might be something working automatically, but I can’t tell till I get 1) to work.
First, you asked two separate questions and should therefore separate then in two separate threads.
To answer your first question: Here is how you can utilise the GraphQL IntelliJ plugin:
You need to create a .graphlconfig file. In Webstorm select your project folder and go to 'File' -> 'New' -> 'GraphQl Configuration File'.
Change the endpoint url to your strapi endpoint.
Visit the GraphQl Tool Window, double click your endpoint and select 'Get GraphQl Schema from Endpoint (introspection)'. This will retrieve the schema file from strapi and save it to schema.graphql.
Now you can run queries against your endpoint, e.g. create a new Scratch File scratch.graphql and run queries against your endpoint or try to figure out how to solve your second question ;)
Thank you for the answer! This was helpful!
Further to this, one query - typically, is .graphlconfig committed to git repo and scratch.graphql ignored from the git repo?
In addition for others looking for a similar solution - you could use values from .env. using the format below:
{
"name": "Strapi GraphQL Schema",
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"Default GraphQL Endpoint": {
"url": "${env:GRAPHQL_HOST}/graphql",
"headers": {
"Authorization": "Bearer ${env:GRAPHQL_TOKEN}",
"user-agent": "JS GraphQL"
},
"introspect": false
}
}
}
}

Shopify script tag: 302 CORB error, script tag redirects to authentication flow

I am stuck. I am using node.js with a custom Shopify app built using Shopify cli.
The script tag I created using graphql keeps throwing a CORB error when it goes live.
createScripts({
variables: {
input: {
src: "https://arcane-spire-11260.herokuapp.com/thanks-script.js",
displayScope: "ORDER_STATUS"
},
},
It seems like I have to authenticate first then it shows but I want it to always show the script tag.
Why does my Heroku server always need to authenticate with the shop before it can display the script?
Add script tag
Throws CORB error
Click on the script tag src link (https://arcane-spire-11260.herokuapp.com/thanks-script.js?shop=littosnz.myshopify.com)
Redirects me to authenticate the store
Script then works
I just want it to be public to everyone all the time. What am I missing here?

How to test graphql + apollo server for upload file mutation using postman?

I using apollo server, and have this mutation :
mutation {
updateData(
file1: fileOne,
file2: fileTwo,
file3: fileThree,
payload: {
id: "7e3583b4-5673-48df-a3cf-44a4ec33f0e1"
}
){
isSuccess
error
data
}
}
I want to test it using postman, because i didnt find any clue test it using graphql playground.
I already find how to test graphql from postman, but it doesn't contains information about file upload. graphql postman
I have an idea from apollo-upload-client to post using multipart-formdata but it still fail.
please help how to test graphql with apollo server for upload file mutation using postman?
thanks
I need to understand about how file upload works in node js (because I use nodejs ini this case)
I install multer for file upload middleware using nodejs and expressjs, if you use other framework or programming language, just try adjust it
In postman I use formdata
you can find the good step by step here
Upload file graphql using postman

How to make introspection from an endpoint file with apollo 2?

with apollo 1.9.2 I'm used to make introspection of the graphql schema using a file as endpoint (that way the server does not need to run).
Here the 1.9 command:
apollo schema:download --endpoint ./schema/def/app.graphql ./schema/lib/schema.json
then thanks to the generated json file I can generate the types that will be used in the client and server code:
apollo codegen:generate --queries ./schema/*.graphql --schema ./schema/lib/schema.json
Now with apollo 2, the apollo schema:download command, renamed apollo service:download, supports only an url. If I do not have that types the server can not start. chicken & eggs issue.
I did not find in the doc how to do that now.
thanks for your help.
I got the answer on gitHub
I must use a config file apollo.config.js with the following
module.exports = {
service: {
localSchemaFile: './path/to/schema.graphql',
},
};
then call
apollo service:download -c ./path/to/apollo.config.js ./schema/lib/schema.json

DateToArray is not defined in couchbase sync gateway

I write the code for couchbase view. follow this https://blog.couchbase.com/understanding-grouplevel-view-queries-compound-keys/
const mapDate = `function(doc, meta) {
emit(dateToArray(doc.updatedAt), {
_id: meta.id,
_rev: meta.rev,
updatedAt: doc.updatedAt
});
}`
and when I call http://localhost:4984/{db}/_design/{ddoc}/_view/{view} I got an error
Error running map function: ReferenceError: dateToArray is not defined
error image
I use sync-gateway version 1.4
What should I do?
In order to be able to query views via the Sync Gateway, you should be creating it through the Sync Gateway REST interface. You cannot query for views directly created on Couchbase Server.
This link should provide more insights into creating and querying views via Sync Gateway
The blog post you're referring to is about Couchbase Server, not Sync Gateway. So, it looks like dateToArray is not a pre-defined function available on Sync Gateway.

Resources