GraphQL .Net Custom Extensions - graphql-dotnet

Is there an example showing how you can include custom extensions in the results of graphql? I am looking for something like this to be returned with all results:
"extensions: {
"numberOfResolvers": 100,
"timeElapsed": 334
}
I am bootstrapping using services:
services.AddGraphQL(options =>
{
options.EnableMetrics = false;
options.ExposeExceptions = true;
})
I am not interested in more detailed metrics that EnableMetrics=true will give. So it would be great if we an globally include some extension logic to have that in in all results.

Looks like the best way to achieve this is using a middleware that adds the extension data after execution. The example is already in the github graphql-dotnet codebase -- looking up EnrichWithApolloTracing and following what it does.

Related

Can we create an rss feed from 2sxc news app?

I've got this customer who asked if it is possible to create an rss feed for the 2sxc news app.
I'm wondering if this is possible in some way, or if anyone has set something like this up...
I can kind of set up an api, which will return xml like output, but it still says:
Feeds should not be served with the "application/json" media type
Just found out .... add
using System.Net.Http
and then create a standard httpresponse with returntypes etc.
var res = Request.CreateResponse(HttpStatusCode.Ok);
res.Content = new StringContent(sb.ToString(), System.Text.Encoding.UTF8, "text/xml");
return res;
That's the spirit :). BTW: In 2sxc 12 we're adding new helpers to stream file results. YOu should then be able to just create an api and return File(contents: xmlObject). Almost done...

How to clear local storage before running each test in WebdriverIO?

I am writing tests for a React based web tool. So I want to clear all local storage such as login information etc. before each test. I have majorly worked in Cypress, where this was just a simple command.
cy.clearLocalStorage();
I am now using WebdriverIO and this is the approach that I was trying out (in the test file).
afterEach(() => {
browser.executeScript('window.localStorage().clear()');
});
However, this doesn't seem to be working. Moreover, I would prefer a global solution, something that I don't have to write in each test. Thanks in advance for the help.
From the WebdriverIO Docs:
// remove the storage item for the given key
client.localStorage('DELETE', 'someKey');
// clear the storage
client.localStorage('DELETE');
You can clear localStorage by running this preset function.
You were almost right in your assumption. I'd suggest using official docs to eliminate minor errors.
Instead of executeScript use https://webdriver.io/docs/api/browser/execute.html
localStorage is not a function, see https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
So it should be
afterEach(() => {
browser.execute('window.localStorage.clear()');
});
P.S.
Assuming you are using WebdriverIO 5 or above.
So, after a lot of time, we realized the problem.
The cy.clearLocalStorage() cleans only the local storage under the baseUrl definition.
If you would like to open multiple pages, you have to explicit define the clearing in the cy.visit() call, like that:
cy.visit(`subdomain.another.domain`, {
onBeforeLoad(win) {
win.localStorage.clear();
},
});
In this case, the local storage for the exact domain, will be deleted.
I hope, this workaround helps.

Shopware 6 custom product fields in tabs

I am completely new to the the Shopware (6) community and I am still learning how to code in Symfony and Vue.js.
After trying some how to's in the developer wiki, I wanted to try some coding by myself.
I would like to combine https://docs.shopware.com/en/shopware-platform-dev-en/how-to/add-admin-new-field and https://docs.shopware.com/en/shopware-platform-dev-en/how-to/new-tab-admin?category=shopware-platform-dev-en/how-to into one functionallity (Product tabs with custom admin fields).
However, when I use the v-model attribute into an input field, the complete tab will turn white and the following error is outputted in the console: product is not defined.
My guess is that the model needs to be imported into the module (I can't find this anywhere into the docs).
Can someone tell me what I have to do to make this work? My current source code can be found here: https://github.com/Millerdigital-matthew/miller-product-upsells
As I understand, you need to change your index.js as follows:
const { Component } = Shopware;
const { mapState } = Component.getComponentHelper();
Component.register('...', {
computed: {
...mapState('swProductDetail', [
'product'
]),
}
});
I looked into your current code.
In your extension you try to bind
v-model="product.manufacturerId"
But in the block you are extending, there is no product defined.
So the solution to this problem, is to define product on your
view/sw-product-detail-upsells

PHPExcel_Settings::setCacheStorageMethod alternative in PhpSpreadsheet

I have this lines in my previous code
$cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_phpTemp;
$cacheSettings = array( 'memoryCacheSize' => '32MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
Now I am trying to migrate to PhpSpreadsheet.
I am able to find class \PhpOffice\PhpSpreadsheet\Settings and methods setCache() and getCache(). But still not able find this options what i have.
Can anyone provide a way or an example to do what i am doing in PHPExcel into PhpSpreadsheet.
Caching was rewritten in PhpSpreadsheet (see documentation). If you need other caching options, you have to write your own PSR-16 cache or use one of the libraries mentioned in the documentation.

Visually testing unusual code paths in ASP.NET WebForms Website

I have a large complex ASP.net WebForm website that I'm working on a visual redesign and am trying to think of good ways to exercise all the code paths in the website so I can see how things look with the redesign.
For example lets say I have a message that only gets displayed if there is an error which rarely happens. Here is an example of what my code might look like:
if (someErrorCondition) {
someControl.Visible = true;
} else {
someOtherControl.Visible = true;
}
This might not be a good way of doing things, but this is a good example of my existing code base I have to work with.
Let us assume for the sake of simplicity that I already have a way of testing one part of the if. The problem is exercising the other part without going through a lot of trouble to setup my environment to create an error.
One idea I had was to extract someErrorCondition into a method and in that method check for some session or request key to see if I want to fake a failure. Maybe wrap it in an #if DEBUG block so that it won't be compiled for production.
Any other ideas for how I might go about testing unusual code blocks on an ASP.net website so I can make sure nothing got left out in the redesign?
I believe the best solution is always the most simple. Since you obviously have access to the code, do a search for the Visible property for each form element within Visual Studio and set each one to true to see how it looks. Once you make the design change then un-comment the original code.
Example:
if (someErrorCondition) {
someControl.Visible = true;
} else {
someOtherControl.Visible = true;
}
TO
/* if (someErrorCondition) {
someControl.Visible = true;
} else {
someOtherControl.Visible = true;
}*/ someControl.Visible = true;
This is not good for testing proper behavior of the form, but will let you see how each element looks for visual design purposes.

Resources