Hello guys i want to ask, so i have JSON response like this:
{
"homeListComponents": [
{
"page": 1,
"listComponents": [
{
"componentName": "HEALTH_PRODUCT",
"componentDescription": "Showing health product component"
},
{
"componentName": "HEALTH_SERVICE",
"componentDescription": "Showing health service component"
},
{
"componentName": "OTHER_HEALTH_SERVICE",
"componentDescription": "Showing other health service component"
}
]
},
{
"page": 2,
...... //same like above
},
{
"page": 3,
...... //same like above
}
]
}
the response was successfully called in graphql using this query:
But, how can i call only page 1 ?
I already tried this query:
But the response is null.
Thank you.
You need implement your graphql resolver in server-side. It decide what result you will get.
In resolver function, your can get the arguments you passed from client.
For your question, I think you need implement a pagination
See these links:
https://graphql.org/learn/pagination/
https://www.apollographql.com/docs/react/features/pagination.html
https://github.com/mrdulin/apollo-server-express-starter/tree/master/src/pagination
Related
Shopify recently announced ShopifyQL for easier accessing of analytics data. However, I'm unclear of how to actually make a ShopifyQL call. They do include an example.
{
# "FROM sales SHOW total_sales BY month SINCE -1y UNTIL today" passes a ShopifyQL query to the GraphQL query.
shopifyqlQuery(query: "FROM sales SHOW total_sales BY month SINCE -1y UNTIL today") {
__typename
... on TableResponse {
tableData {
rowData
columns {
# Elements in the columns section describe which column properties you want to return.
name
dataType
displayName
}
}
}
# parseErrors specifies that you want errors returned, if there were any, and which error properties you want to return.
parseErrors {
code
message
range {
start {
line
character
}
end {
line
character
}
}
}
}
}
However, using the GraphiQL tool to run the query hits a number of errors:
{
"errors": [
{
"message": "Field 'shopifyqlQuery' doesn't exist on type 'QueryRoot'",
"locations": [
{
"line": 3,
"column": 3
}
],
"path": [
"query",
"shopifyqlQuery"
],
"extensions": {
"code": "undefinedField",
"typeName": "QueryRoot",
"fieldName": "shopifyqlQuery"
}
}
]
}
I also tried making an authenticated call with the example query above using my app's Node server, but ran into the same issues.
What am I missing here?
Looks like it only works with the unstable version currently:
https://"+shop_name+".myshopify.com/admin/api/unstable/graphql.json
Got a successful response with this.
Is this still working for you?
https://storename.myshopify.com/admin/api/unstable/graphql.json
This was working for past 6 months. but now it getting access denied.
"code": "ACCESS_DENIED",
"documentation": "https://shopify.dev/api/usage/access-scopes",
"requiredAccess": "read_reports access scope, read_customers access scope, read_fulfillments access scope, read_inventory access scope, read_orders access scope, read_products access scope and read_all_orders access scope"
}
I am just doing a Q&A web app like SO. I want to count the number of views the page viewed by the user like SO 12 views.
I used loopback as a server and i have a model questions which contain numberOfViews property. Here is the problem that i faced, by default loopback generates /questions/{id} endpoint and this endpoint finds the question by id and returns it but in addition to returning the question i want to increment the numberOfViews property of the question. How to accomplish that?
questions model
[
{
"title": "string",
"body": "string",
"tags": [
"string"
],
"date": "string",
"numberOfViews" : 0,
"questionerId": "string",
"answers": [
"string"
],
"voteNumber": 0,
"shortComments": [
"string"
],
"usersUpVoted": [
"string"
],
"usersDownVoted": [
"string"
],
"id": "string"
}
]
Any help appreciated.
You can try hook for this purpose.
MyModel.observe('access', function logQuery(ctx, next) {
console.log('Accessing %s matching %s', ctx.Model.modelName, ctx.query.where);
next();
});
Note:
You can check what you get in ctx and use your custom condition in observe to fulfill your requirement. As i have not test it.
reference link : github , document
If you need to increment the numberOfViews property only on "findById" remote method better to use after remote hook:
Model.afterRemote('findById', (ctx, result, cb) => {
// You code here...
});
Or the same using async/await (you should return promise here, or you code freeze)
Model.afterRemote('findById', async (ctx, result) => {
// You code here...
});
This is my JSON Response of my Rest API.
{"ListClientResponse": {
"Header": {"CMMHeader": {"CorrelationId": "cmm:CorrelationId"}},
"Result": {
"ResponseCode": "CM-N-0000",
"ResponseMessage": "No errors and warnings."
},
"ListClient": {"Client": [
{
"OrganizationId": 523,
"OrganizationName": "OrgX1518521.com",
"OrganizationDomain": "X1518521.com"
],
"RoleId": "AdminRole",
"RoleName": "Admin"
}
},
I want to save Organization Id and OrganizationDomain from my JSON Response in a variables or something so that I can use these values later in my all JSON requests.
This is my JSON request.
var myCreateUserRequest = {
"CreateUserRequest": {
"Header": {
"CMMHeader": {
"CorrelationId": 5454354}},
"ClientContext": {
"OrganizationId": **theOrgId,**
"OrganizationDomain": **theDomain,**
},
"User": {
"UserName": aUser.Username,
"UserPassword": aUser.Password,
"UserStatus": "Active",
"RoleId": "Member"
}
}
}
In my JSON request, inside the field of OrganizationId and OrganizationDomain I want to pass that organizationID value and OrganizationDomain value that I have saved from my JSON Response in a varibale. I want to save it in a way so that organizationId and OrganizationDomain can be accessible in my whole ANGULAR JS project and I can pass it in my any JSON request. How can I do that. Please tell me any suggestion.
Best practice in this case tells to create a service. Becouse services are singleton in Angular, you can set a vale and inject in yours services/controllers and have access to the value.
I made a parse.com get request, the returned data is stored in:
$scope.tastes = data.results
{
"createdAt": "2016-03-16T07:39:15.745Z",
"objectId": "Cmg8GdOv2Z",
"updatedAt": "2016-03-16T07:39:15.745Z",
"user": {
"__type": "Pointer",
"className": "_User",
"objectId": "vYOsndWlto"
},
"userTastes": [
{
"actualite": {
"checked": true
},
"economie": {
"checked": true
},
"entrepreneuriat": {
"checked": false
}
}
]
}
Well, I want to get userTastes array.
I've tried
.success(function (data, status) {
$scope.tastes = data.results.userTastes;
console.log($scope.tastes);
})
However nothing is returned. I think that I'm missing something.
My question : How do I get userTastes in $scope.tastes ?
I writing a separate answer because I believe this needs further explanation and not just the fix to your problem.
You only provided an object response in your question, but apparently you are getting an array response from your server, while you can directly access object fields, on array objects you need to access the position first, Ex:
$scope.objectResponse = {"foo":"bar"};
console.log($scope.objectResponse.foo); // Will print "bar"
in contrast array responses:
$scope.arrayResponse = [{"foo":"bar"}];
console.log($scope.arrayResponse[0].foo); // Will print "bar"
Just make sure you are getting the response you want from your server.
results[0].userTastes work worked perfectly thanks !
If someone have a tutorial link or good course about array and objects in JS because I'm a little bit confused about that.
Have a good day !
I'm currently trying to put something together with ember + emberdata + router + asp.net web api. Most of it seem to work, however I stuck in an error message I get when ember-data tries to findAll through the adapter for my models.
In my backend I have a model like this (C#):
public class Genre {
[Key]
public int Id { get; set; }
[Required]
[StringLength(50, MinimumLength=3)]
public string Name { get; set; }
}
Which in my app I represent it like this using ember-data:
App.Genre = DS.Model.extend({
id: DS.attr("number"),
name: DS.attr("string")
}).reopenClass({
url: 'api/genre'
});
I have also a Store defined in my App using the RESTAdapter like so:
App.store = DS.Store.create({
revision: 4,
adapter: DS.RESTAdapter.create({
bulkCommit: false
})
});
And the store is used in my controller as below:
App.GenreController = Ember.ArrayController.extend({
content: App.store.findAll(App.Genre),
selectedGenre: null
});
The router is defined as
App.router = Em.Router.create({
enableLogging: true,
location: 'hash',
root: Ember.Route.extend({
//...
genre: Em.Route.extend({
route: '/genre',
index: Ember.Route.extend({
connectOutlets: function (router, context) {
router.get('applicationController').connectOutlet('genre');
}
})
}),
//...
})
})
When I run my application, I get the following message for every object that has this same structure:
Uncaught Error: assertion failed: Your server returned a hash with the
key 0 but you have no mappings
For reference, here's the json the service is returning:
[
{
"id": 1,
"name": "Action"
},
{
"id": 2,
"name": "Drama"
},
{
"id": 3,
"name": "Comedy"
},
{
"id": 4,
"name": "Romance"
}
]
I cannot tell exactly what the problem is and since the assertion is mentioning that I need mapping, I'd like to know:
What this mapping is and how to use it.
Since the returned json is an array, should I be using a different type of controller in my app ,or is there anything I should know about when working with this type of json in ember-data? or should I change the JsonFormatter options in the server?
Any help is welcome.
I can definitely add more information if you feel this isn't enough to understand the problem.
EDIT: I've changed a few things in my backend and now my findAll() equivalent action in the server serializes the the output as the following json:
{
"genres": [
{ "id": 1, "name": "Action" },
{ "id": 2, "name": "Drama" },
{ "id": 3, "name": "Comedy" },
{ "id": 4, "name": "Romance" }
]
}
But I still can't get it to populate my models in the client and my error message has changed to this:
Uncaught Error: assertion failed: Your server returned a hash with the
key genres but you have no mappings
Not sure what else I might be doing wrong.
The method that throws this exception is sideload and checks for the mappings like this:
sideload: function (store, type, json, root) {
var sideloadedType, mappings, loaded = {};
loaded[root] = true;
for (var prop in json) {
if (!json.hasOwnProperty(prop)) { continue; }
if (prop === root) { continue; }
sideloadedType = type.typeForAssociation(prop);
if (!sideloadedType) {
mappings = get(this, 'mappings');
Ember.assert("Your server returned a hash with the key " + prop + " but you have no mappings", !!mappings);
//...
This call sideloadedType = type.typeForAssociation(prop); returns undefined and then I get the error message. The method typeForAssociation() checks for the for 'associationsByName' key which returns an empty Ember.Map.
Still no solution for this at the moment.
By the way...
My action is now like this:
// GET api/genres
public object GetGenres() {
return new { genres = context.Genres.AsQueryable() };
}
// GET api/genres
//[Queryable]
//public IQueryable<Genre> GetGenres()
//{
// return context.Genres.AsQueryable();
//}
I had to remove the original implementation which gets serialized by json.NET as I could not find config options to produce a json output as Ember-Data expects ( as in {resource_name : [json, json,...]}). Side effect of this is that I've lost built-in OData support, but I'd like to keep it. Does anyone know how could I configure it to produce different json for a collection?
The mapping can be defined in the DS.RESTAdapter. I think you could try to define something like this:
App.Store = DS.Store.extend({
adapter: DS.RESTAdapter.create({
bulkCommit: true,
mappings: {
genres: App.Genre
},
// you can also define plurals, if there is a unregular plural
// usually, RESTAdapter simply add a 's' for plurals.
// for example at work we have to define something like this
plurals: {
business_process: 'business_processes'
//else it tries to fetch business_processs
}
}),
revision: 4
});
Hope this resolves your problem.
Update:
At this time, this is not well documented, I don't remember if we found it by ourself reading the code, or perhaps Tom Dale pointed on it.
Anyway, here is the point for plurals
For the mappings, I think we were driven by the same error as you, and either we tried, either Tom teached us about this.
The RESTAdapter expects the returned JSON to be of the form:
{
"genres": [{
"id": 1,
"name": "action"
},{
"id": 2,
"name": "Drama"
}]
}
The tests are a good source of documentation, see https://github.com/emberjs/data/blob/master/packages/ember-data/tests/unit/rest_adapter_test.js#L315-329
I'm using Ember Data rev. 11 and it seems that the plurals config in DS.RESTAdapter.create never works. I looked into the codes and found a solution as following:
App.Adapter = DS.RESTAdapter.extend({
bulkCommit: false
})
App.Adapter.configure('plurals', {
series: 'series'
})