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.
Related
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.
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
}
}
}
}
I have a Lambda function, attached to an API Gateway endpoint, that lists the items under an ID in DynamoDB.
I've built my function using the Serverless Framework. When I invoke the function locally (serverless invoke local ...) it works fine. When I test it manually on the AWS Lambda console, it works fine, but when I call it from the API Gateway, it doesn't work.
It's configured to use this payload: (What I've used for testing)
{
"requestContext": {
"identity": {
"cognitoIdentityId": "468648c5-b135-4075-910a-8a648d66e67d"
}
}
}
In my app, I use the aws-amplify package. This is how I call the endpoint:
data = await API.get('endpoint-name', '/endpoint', {
body: {
requestContext: {
cognitoIdentityId: '468648c5-b135-4075-910a-8a648d66e67d'
}
}
});
Here, I get a 403 error. If I call it without the extra data, i.e:
data = await API.get('endpoint-name', '/endpoint');
I get an empty list [ ], but no error. Does aws-amplify automatically populate the cognitoIdentityId field? I'm following the serverless-stack tutorial, and they kinda gloss over this.
I also have CloudWatch set up, and I cannot see anything funky there. Any ideas on how to fix / debug this issue?
Cheers!
Ah - I think I solved it!
I configured my endpoint to take parameters from the body of a GET request, however (I think) either aws-amplify or the API Gateway doesn't support a request body when performing a GET. I noticed this by manually testing the API Gateway (Which I hadn't done before), and it stated Request Body is not supported for GET methods.
So I think I'll have to pass my parameters in the URL itself.
Context to this post is I'm a java developer attempting to teach myself Ember. It isn't going well. I realize this question is pretty vague so I apologize, I'm not even sure what I should be asking...
I need to pull data into a model, i.e. via some sort of query, from a heroku json endpoint. In the application.js file, I have the following:
import DS from ‘ember-data’;
export default DS.JSONAPIAdapter.extend({
host: 'https://cag-brain.herokuapp.com'
});
Ideally I would like to pull this data into a user model, then display that data on a page as a sort of proof of concept. This unfortunately gets me nothing. Nor am I even sure I'm going about this correctly. Should I be doing something different than attempting to use Host Customization? Any guidance would be much appreciated!
There are different things involved for retrieving records via ember-data.
First of all you should define your models:
// app/models/post.js
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string')
});
You should retrieve records in a model hook of a route.
// app\routes\posts.js
import Route from '#ember/routing/route';
export default Route.extend({
model() {
return this.get('store').findAll('post');
}
});
Then you should configure your api host and maybe a namespace. You included that step in your question:
// app/adapters/application.js
import DS from ‘ember-data’;
export default DS.JSONAPIAdapter.extend({
host: 'https://cag-brain.herokuapp.com'
});
If your api does not implement JSON Api specification you need to customize your serializer and adapter. Ember-data ships with a RESTAdapter/RestSerializer additionally to the default adapter and serializer which implements JSON Api spec. There is also one abstract adapter and serializer If you need to start from scratch. Before that I would definitely have a look if there is any community adapter/serializer fitting your needs.
To decouple api and client development and to speed up tests I would recommend ember-cli-mirage which allows you to mock your api.
I'm new to backbone.js and I've read other solutions to similar problems but still can't get my example to work. I have a basic rails api that is returning some JSON from the url below and I am trying to access in through a backbone.js front end. Since they are one different servers I think I need to use a 'jsonp' request. I'm currently doing this by overriding the sync function in my backbone collection.
Api url:
http://guarded-wave-4073.herokuapp.com/api/v1/plans.json
sync: function(method, model, options) {
options.timeout = 10000;
options.dataType = 'jsonp';
options.url = 'http://guarded-wave-4073.herokuapp.com/api/v1/plans.json'
return Backbone.sync(method, model, options);
}
To test this I create a new 'plans' collection in my chrome console using "plans = new Plans()" and then "plans.fetch()" to try and get the JSON.
When I call plans.models afterwards I still have an empty array and the object that returns from plans.fetch() doesn't seem to have any json data included.
Any ideas where I'm going wrong?
I have had the same problem before. You should not have to override your sync method.
Taken from Stackoverflow Answer
"The JSONP technique uses a completely different mechanism for issuing HTTP requests to a server and acting on the response. It requires cooperating code in the client page and on the server. The server must have a URL that responds to HTTP "GET" requests with a block of JSON wrapped in a function call. Thus, you can't just do JSONP transactions to any old server; it must be a server that explicitly provides the functionality."
Are you sure your server abides to the above? Test with another compatible jsonp service (Twitter) to see if you receive results?
Have you tried overriding the fetch method as well?
You should add ?callback=? to your api url in order to enable jsonp