How do I change a schema, that i got via introspection?

I am currently learning and testing around with GraphQL. Richt now I am building a layer between the actual graphql-endpoint and an imaginary frontend (for example a storefront).

Here what I did up to this point (this is all tested and working):

  1. Get schema from the actual endpoint (introspection query…).
  2. Build a “proxy” resolver that sends the requests that are made to the layer to the actual graphql-endpoint & build a executable schema using wrapSchema() from graphql-tools/wrap:
const schema = wrapSchema({
 schema: serverSchema,
 executor,
 createProxyingResolver: applicationProxyResolver,
});
  1. And here I am stuck: Now I want to filter out one query and change where the request is sent to. (basically sending the request to another endpoint)

In all examples I looked into they just change it in the schema, but I can’t/don’t want to do that as exactly that is what I want to avoid doing. I want to change the schema in my layer, not the original one on the actual graphql-endpoint.

Any ideas as to how i can tackle that issue?

console.log displays “undefined” in the end of an array of objects

I wanted to display a simple array’s items on the console, using foreach. It dispalys all the items(it’s OK), but it displays “cars : undefined” at the end.
I dont want to display “cars : undefined”.
How to do ?

var cars = [{
    year: 2011,
    type: "Volvo"
}, {
    year: 1999,
    type: "Volvo"
}, {
    year: 2003,
    type: "Volvo"
}];
console.log("1");

console.log("cars : " + cars.forEach(a => console.log(a)));
console.log("2");

Show data from back using python with ajax in datatable

I got a problem when I want to show Datatable. I’m using python to return data

return jsonify({'data': {'1': list_data, '2':list_data2}})

Then I have datatable :

tableUtama = $('#tableUtama').DataTable({
    'scrollY': '250px',
    'scrollX': true,
    'searching': false,
    'ordering': false,
    'info': false,
    'paging': false,
    'autoWidth': true,
    "ajax": {
      "url": "/processData",
      "dataType": "json",
      "dataSrc": function (data) {
          return data.data['1']
        }
        "columnDefs": [
        { 'targets': 0, "data": "kd_toko" },
        { 'targets': 1, "data": "name_toko"},
        { 'targets': 2, "data": "loc_toko" },
        { 'targets': 3, "data": "type_toko" },
        { 'targets': 4, "data": "dates" }]
         }
         })

All data inside data.data[‘1’] not showing. but only show row
here's result

please help me

TinyMCE replacing visual content

I have built an interface for creating math equations and want to implement it in tinymce. At MathType I have seen that they can insert the equation as mathml but then when expecting the DOMElements one sees that they insert an Image with base64/xml as source that represents the equation while preserving the mathml in a data-attribute (I suppose for later editing). Now I want to build something similar that 1. replaces mathml on load and 2. replaces mathml on insert of a new equation.

My Question:
How can I replace nodes so that they are changed visually but when I save the document or inspect it in the code editor it still shows the original mathml instead of the img?

React-chartjs-2: How to display timeline of released dates over 5 past years in Bar Chart?

Given a structure like this

const products = [
  {
    id: 1,
    status: "released"
  },
  {
    id: 2,
    status: "in progress"
  },
  {
    id: 3,
    status: "in progress"
  },
  {
    id: 4,
    status: "released"
  },
  {
    id: 5,
    status: "released"
  }
];

I’m trying to display a timeline of released dates over 5 past years.
As you can see, in the array of objects above, status property can be different. So my goal is to display the timeline for released objects in a chart.
I created an objects for labels like this
const labels = ["2018", "2019", "2020", "2021", "2022"],
but can’t figure out to implement it in the chart.
Here is Code example and sandbox link

import React from "react";
import {
  Chart as ChartJS,
  CategoryScale,
  LinearScale,
  BarElement,
  Title,
  Tooltip,
  Legend
} from "chart.js";
import { Bar } from "react-chartjs-2";
import faker from "faker";

ChartJS.register(
  CategoryScale,
  LinearScale,
  BarElement,
  Title,
  Tooltip,
  Legend
);

export const options = {
  responsive: true,
  plugins: {
    legend: {
      position: "top" as const
    },
    title: {
      display: true,
      text: "Chart.js Bar Chart"
    }
  }
};

const products = [
  {
    id: 1,
    status: "released"
  },
  {
    id: 2,
    status: "in progress"
  },
  {
    id: 3,
    status: "in progress"
  },
  {
    id: 4,
    status: "released"
  },
  {
    id: 5,
    status: "released"
  }
];

const labels = ["2018", "2019", "2020", "2021", "2022"];

export const data = {
  labels,
  datasets: [
    {
      label: "Dataset 1",
      data: labels.map(() => faker.datatype.number({ min: 0, max: 1000 })),
      backgroundColor: "rgba(255, 99, 132, 0.5)"
    },
    {
      label: "Dataset 2",
      data: labels.map(() => faker.datatype.number({ min: 0, max: 1000 })),
      backgroundColor: "rgba(53, 162, 235, 0.5)"
    }
  ]
};

export function App() {
  return <Bar options={options} data={data} />;
}

Any help will be appreciated

Find out which console.log() prints the log

I am working on a big project with lots of co-workers and while debugging sometimes finding the code that prints terminal logs gets difficult.

So i am looking for a way (or an extension) to find source of the logs from the terminal.

For example i want to right click on the line of the log from the terminal and click ‘go to source’ and it will bring the file and focus on the line where that log is printed.
(I am using VSCode)

Any one have any tricks for this situation?

Thanks.

How to work with Google Spanner Date type in Javascript?

I have multiple tables in Google Cloud Spanner with columns of type Date. Inserting entries with specified dates is not a problem, and reflects appropriately in the database. However, retrieving entries from the database into the Javascript frontend is where the issue lies. I can’t seem to figure out in which format these date fields are. A seemingly infinitely nested object is returned, which I can’t make sense of.

I’ve tried

console.log(date.toJSON());
console.log(date.toString());
console.log(new Date(date));

where date is the Spanner Date object in question, but none of these attempts have yielded any insightful results.

Any advice or information on the matter would be appreciated. Thanks in advance!

.NetCore Telerik UI, Grid header centering

Hi I’m using telerikUI for our app, My question is simple, in header row we got checkbox which is select/deselect all rows. we got 2 file, css and js. here’s my codes

in js file for heaeder

columns.unshift({
               width: "25px", 
                headerAttributes: {
                    style: "background-color:red;text-align:center"
                } ,
                attributes: { style: "text-align:center" },
});

in css

.k-grid .k-grid-header .k-header .k-link {
    height: auto;
}

.k-grid .k-grid-header .k-header {
    height: auto;
    white-space: nowrap;    
}

Result

i just want to give min width and center it while expanding horizontally

Thank you

I think theres something in the way, and that thing block to centering

Here Rounting V7 still useable?

Is the here Rounting v7 Api still useable? If a want to make a example request from the website :

“https://route.ls.hereapi.com/routing/7.2/calculateroute.json?apiKey={YOUR_API_KEY}&waypoint0=geo!52.5,13.4&waypoint1=geo!52.5,13.45&mode=fastest;car;traffic:disabled”

I get Error code 403, these credentials do not authorize access.

On other request my api Key works fine

Javascript image slideshow iteration – why is the last image first

I am trying to create a small slideshow. The slideshow consists of six images each with their own caption. There is also one static general caption.

The code below works but it shows the last image first, then skips the first image and iterates through the rest. After the first round everything is in order, so why is this happening please?

CSS

.imwrap {
    max-width: 500px;
    margin: 0 auto;
    position: relative;
    font-family: Roboto;
}

.imgsx {
    position: absolute;
    transition: opacity 1.5s ease-in;
    max-width: 99%;
    border-radius: 13px;
}

.text {
    color: white;
    font-weight: bolder;
    font-size: 15px;
    padding: 8px 12px;
    position: absolute;
    margin-top: 65%;
    left: 50%;
    transform: translate(-50%);
    text-align: center;
    transition: opacity 1.5s ease-in;
    width: fit-content;
    z-index: 2000;
    opacity: 0;
    display: block;
    text-align: center;
}

.numbertext {
    color: blue;
    font-size: 12px;
    padding: 8px 12px;
    position: absolute;
    top: 0;
    background-color: rgba(255, 255, 255, 0.6);
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
    z-index: 100;
}

.imgsx+.imgsx {
    opacity: 0;
}

HTML

<div class="imwrap">
  <div class="numbertext">with kind permission from picturesofengland.com</div>  
  <img class="imgsx" src="./trip/railway.webp" alt="Railway">
  <div class="text">Swanage preserved railway - by Jack Rickard &copy;</div>
  <img class="imgsx" src="./trip/boats.webp" alt="Boats">
  <div class="text">Swanage - by Jenny Fairbrother &copy;</div>
  <img class="imgsx" src="./trip/night.webp" alt="Night time">
  <div class="text">Night time on the beach - by Stephen Williams &copy;</div>
  
  <img class="imgsx" src="./trip/training.webp" alt="Training ship">
  <div class="text">Training in Swanage Harbour &copy;</div>
  <img class="imgsx" src="./trip/buffet.webp" alt="Buffet car">
  <div class="text">Buffet Car, Swanage Station - Jenny Fairbrother &copy;</div>
  <img class="imgsx" src="./trip/sunny.webp" alt="Sunny evening">
  <div class="text" style="opacity:1">A Sunny evening in Swanage - by Jill Giles &copy;</div>
</div> 

javascript

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> 
<script>
var current = 0,
  slides = document.getElementsByClassName("imgsx");
  caps = document.getElementsByClassName("text");
setInterval(function() {
    for (var i = 0; i < slides.length; i++) {
        slides[i].style.opacity = 0;
        caps[i].style.opacity = 0;
    }
    current = (current != slides.length - 1) ? current + 1 : 0;
    slides[current].style.opacity = 1;
    caps[current].style.opacity = 1;
}, 5000);
</script>

Sinon stub won’t stub the function

I have the following abstract class which uses the “fs-extra” library:

import { ClassConstructor, instanceToPlain, plainToClass } from 'class-transformer';
import { validateOrReject } from 'class-validator';
import fs from 'fs-extra';

import getLog from '../../helpers/logger';

export default abstract class AppConfigService<T extends object> {
    public async setConfig(config: T) {
        const logger = getLog(`${AppConfigService.name}/${this.setConfig.name}`);

        logger.info(`About to set app-config file with configuration:n${JSON.stringify(config, null, 2)}`);

        const currentFileObject = instanceToPlain(this.fileObject);

        logger.info(`Current app-config configuration is:n${JSON.stringify(currentFileObject, null, 2)}`);

        const validatedConfig = await this.validatedConfig({ ...currentFileObject, ...config });

        logger.info('Provided app-config configuration is valid');

        const filePath = await this.getFilePath();

        logger.info(`Got app-config file path: "${filePath}""`);

        await fs.outputJson(filePath, validatedConfig);

        this.fileObject = validatedConfig;

        logger.info('Successfully set app-config provided configuration');
    }
}

This is only snippet as I don’t find the rest of the class relevant.

Then I have the following class:

import path from 'path';

import AppConfigService from '../../services/app-config';
import ConstantsModule from '../constants';
import { UserAppConfigDto } from './classes/user-app-config.dto';
import { APP_CONFIG_FILE_NAME } from './models/user-app-config';

export default class UserAppConfigService extends AppConfigService<UserAppConfigDto> {
    protected classConstructorRef = UserAppConfigDto;

    protected async getFilePath() {
        const userConfigFolderPath = await ConstantsModule.service.getUserConfigFolder();
        const appConfigFilePath = path.join(userConfigFolderPath, APP_CONFIG_FILE_NAME);

        return appConfigFilePath;
    }
}

And then I try to test the last class:

import { doesNotReject, rejects } from 'assert';

import sinon from 'sinon';
import { expect } from 'chai';
import fs from 'fs-extra';

import UserAppConfigModule from '../../app/modules/user-app-config';
import UserAppConfigService from '../../app/modules/user-app-config/user-app-config.service';

describe('[modules/user-app-config.module.ts]', () => {
    const sandbox = sinon.createSandbox();

    afterEach(sandbox.restore);

    describe('setConfig()', () => {
        it('should throws when "fs-extra/outputJson" rejects', async () => {
            sandbox.stub(fs, 'outputJson').rejects();

            await rejects(UserAppConfigModule.service.setConfig({}));
        });

        it('should succeed when "fs-extra/outputJson" resolves', async () => {
            sandbox.stub(fs, 'outputJson').resolves();

            await doesNotReject(UserAppConfigModule.service.setConfig({}));
        });
    });

});

But for some reason sinon does not stub fs-extra, the function outputJson. Why is that? I suspect the fs-extra/outputJson is not stubbed because of any context issues?
My first test fails because the function wasn’t stubbed

Javascript Uncaught ReferenceError: createDatatable is not defined

I am trying to create data table in .net core view. However, I am getting error when I check console.

Error like in below.

Uncaught ReferenceError: createDatatable is not defined

I checked If I forgot some cdn to add but I could not find.

Javascript code :

@section Scripts{
    <script>
        createDatatable({
            tableId: 'table1',
            controller: 'User',
            action: 'LoadTable',
            columns: [
                {
                    data: "Id",
                    name: "eq",
                    visible: true,
                    searchable: true
                },
                {
                    data: "FirstName",
                    name: "co",
                    searchable: true
                },
                {
                    data: "LastName",
                    name: "co",
                    searchable: true
                },
                {
                    data: "UserName",
                    name: "co",
                    searchable: true
                },
                {
                    data: "Email",
                    name: "co",
                    searchable: true
                },
                {
                    sortable: false,
                    class: 'text-center',
                    searchable: false,
                    render: function (data, type, row, meta) {
                        return '<a class="btn btn-outline-success btn-sm" href="/User/ChangePassword/' + row["Id"] + '" title="Şifre Değiştir"><i class="icon-lock"></i></a> &nbsp;&nbsp;&nbsp;<a class="btn btn-outline-primary btn-sm" href="/User/Edit/' + row["Id"] + '" title="Düzenle"><i class="icon-pencil"></i></a> &nbsp;&nbsp;&nbsp;<a class="btn btn-outline-danger btn-sm" href="/User/Delete/' + row["Id"] + '" title="Sil"><i class="icon-trash"></i></a>';
                    }
                }
            ],
            primaryKey: "Id",
            hasCostumActionsColumn: true
        });
    </script>
}

How to get relative path to an imported file in node.js

I have the following file:

import {something} from '../../something';

something.do();

And I want to get something‘s relative path as a string, but dynamically rather than to write it implicitly. Something like this:

import {something} from '../../something';

getPath(something); // will return '../../something'

something.do();

What are my options? Is it even possible?

Any way to send MediaStream or its frames to webworker?

I am working on a webrtc comminucation app, as part of this app I need to make changes (resize, change background, blue background ,…) to the webcam image before sending it to the subscribers …

This is my solution for now :
1 – set stream to a in memory video element
2 – when play starts start a loop with settimeout to repeat No.3
3 – render video on canvas
4 – capture canvas stream

So far so good.
But when the tab is inactive/hidden/invisible the settimeout is throttled to 1 loop per second 🙁 …

Only other solution I have found is to use MediaStreamTrackProcessor , It works but lacks the browser support that I need (Firefox, Safari,…)

I tried using webworkers but can’t sent a stream to worker and can’t capture a stream inside a worker neither 🙁

So Any way to send MediaStream or its frames(continuously) to webworker ? Or Is there anyway (cross browser) to get frames from MediaStream continuously(so I won’t need settimeout) ?