Can I implement custom 'query' function on composer - hyperledger-composer

Can I implement custom 'query' function on composer? in my understanding, transaction processor is 'invoke' and cannot return data 
synchronously. how do i add query logic after getting Assets?

Composer v0.12.2 exposes named queries as GET methods from the composer-rest-server. Simply define your business network queries using the Composer Query Language, start the composer-rest-server for your network and it will automatically generate the REST endpoints that execute your queries and return the results.
This is described in detail here:
https://hyperledger.github.io/composer/tutorials/queries.html

Related

Server-side request to upload file using Keystone

I have a Keystone list schema that has a field of type 'File'.
So, a GraphQL mutation to update entity has an Upload GraphQL type for argument that corresponds to this field.
I need to execute update mutation using executeGraphql in server environment.
Did not found any plug-and-play solution for that.
One way, we are using for our test environment is to create an instance of ApolloClient and pass a link with createUploadLink from apollo-upload-client library. But, AFAIK, this approach will trigger real HTTP request.
It seems, like better way is to use existing instance of Keystone class on server side…
Any recommendations?
Thank you.
Cheers!

How to mock User model within composer package development tests?

I started creating a laravel 5.8 based modular API framework for our company which should be extended using composer packages.
Now I stumbled over the problem to test each package by itself (each package has it's own GIT project of course) if the package needs to have access to the User model given in the base framework (App/Models/User).
There will be various packages naturally depending on the User model such as specific auth modules.
Unfortunately testing also gets more complex because we are using GraphQL (Lighthouse).
So how should this be done? I tried mocking App/Models/User with a User model contained in the tests folder of my package, but this did not work as expected:
$this->userMock = \Mockery::mock('CompanyName\\PackageName\\Tests\\User');
$this->app->instance('App\\Models\\User', $this->userMock);
When, after that, posting a GraphQL request the resolver method throws a Class App\Models\User does not exist error.
I am quiet new to testing with phpunit so maybe I am just missing something here?
Edit:
I just found out that the error message above is displayed because the User model is also referenced within the GraphQL schema file.
So I there is any solution out there it has to somehow "emulate" the not existing User model class for the whole request lifecycle I guess...
Ok I finally solved my problem which was more conceptual wise I guess. As the user model is pretty strongly tied to the (core) package I want to test, I have now moved the model into the package itself and removed it from the base project.
This has the advantage that the "end user developer" doesn't even see and has to cope with the user model which is handles by the package anyway.
Now I can test the package independently and only have to put a line of documentation into the README to tell, that a user has to change the auth.providers.users.modelvalue to let laravel use the appropriate model (e.g. CompanyName\\PackageName\\Models).
If there will be other packages extending the user model, they will have to depend on the core package (which they should either way) and can extend the model class and tell the user to update auth.providers.users.model again. This way it is also quiet transparent to see which user model is used currently.
For the GraphQL / Lighthouse part I have added the following code to the boot method of the package's service provider to make lighthouse know about new models within the package automatically:
$lighthouseModels = config('lighthouse.namespaces.models');
array_push($lighthouseModels, 'CompanyName\\PackageName\\Models');
config([
'lighthouse.namespaces.models' => $lighthouseModels
]);
This can be repeated for every package adding models as well so lighthouse knows about all of them.

How to integrate Strapi with a SSG using lifecycle callbacks?

I'm using Strapi together with a static site generator (Gatsby), and I'm trying to automate the "rebuild" process whenever you make any modifications in the CMS content.
I'm trying to use the lifecycle callbacks mentioned in the Strapi documentation to do this: https://strapi.io/documentation/3.x.x/guides/webhooks.html
The problem is that these callbacks are being called multiple times in different models. For example, the "afterUpdate" callback is getting called 5 times for the 5 models I have.
I only want to execute the build trigger function only once per change, is there a way to do that?
This seems to be the correct behavior of Strapi lifecycle callbacks: https://github.com/strapi/strapi/issues/1153
Actually there is no issue here. In fact when you create an entry, we first create the entry and then update to handle relations. That's why many events are trigger on create entry.
The documentation is misleading and I don't think lifecycle methods should be used to trigger the SSG builds.
A better choice I found is to use the ContentManager.js controller, it's located in: plugins/content-manager/controllers/ContentManager.js
The create, update and delete functions get called only once per request, so this is a better place to trigger a SSG build:
delete: async ctx => {
ctx.body = await strapi.plugins['content-manager'].services['contentmanager'].delete(ctx.params, ctx.request.query);
// This is just a request to another service
// that triggers the SSG build.
await build.triggerSSGBuild();
},

Where to put ajax request in Ember tutorial app?

I want to add "Weather: 24C" to the rental-listing component of the super-rentals tutorial app.
Where would be the "best-practices" place to put this ajax request?
Ember.$.getJSON(`http://api.openweathermap.org/data/2.5/weather?q=${location}&APPID=${apiKey}`)
.then(function(json) {
return JSON.parse(json).main.temp;
});
Do I need to add a component, add a model, add a service, add a second adapter, modify the existing adapter? Something else? All of these? Is the problem that the tutorial uses Mirage? I ask this because when I think I'm getting close, I get an error like this:
Mirage: Your Ember app tried to GET
'http://api.openweathermap.org/data/2.5/weather?q=london&APPID=5432',
but there was no route defined to handle this request.
Define a route that matches this path in your
mirage/config.js file. Did you forget to add your namespace?
You need to configure mirage to allow you making calls to outside in case mirage is active; what I mean is using this.passthrough function within mirage/config.js, that is explained in api documentation quite well.
Regarding your question about where to make the remote call is; it depends:
If you need the data from the server to arrive in case a route is about to open; you should prefer putting it within model hook of the corresponding route.
If you intend to develop a component that is to be reused from within different routes or even from within different applications with the same remote call over and over again; you can consider putting the ajax remote call to a component. Even if that is not a very common case usually; it might be the case that a component itself should be wrapped up to fetch the data and display it by itself for reusing in different places; there is nothing that prevents you to do so. However by usually applying data-down action-up principle; generally the remote calls fall into routes or controllers.
Whether using an ember-data model is another thing to consider. If you intend to use ember-data; you should not directly use Ember.$.ajax but rather be using store provided by ember-data and perhaps providing your custom adapter/serializer to convert data to the format ember-data accepts in case the server do not match to the formats that ember-data accepts. In summary; you do not need to use models if you use pure ajax as you do in this question.

How to handover a custom rule for SonarQube to identify JavaScript constructors?

I was working on client side MVC framework like Angular JS. Be a part of project I have written some services to handle the restful client requests and responses by using Angular Api. Right now I am doing some code quality task by using SONAR Tool. But as per Angular JS Api service having one function we can call it is as a constructor with same name of service. For example
angular.module('modulename').factory('ServiceName',[function(){
function ServiceName() { }]);
Now issue with SonarQube. SonaQube reading this function name as a normal function name (serviceName) basing on some normal function hungarian notation rules but If I change this function name as a normal function name then functionality is not working as per Angular JS Api standards. So now I need to handover one custom rule to SONAR for omitting of checking these constructor name as normal function name. So can anyone please suggest me any ways to write custom rule for handling such kind of scenarios. Thanks in advance?

Resources