I am following the how to graphql tutorial where I am setting up a simple graphql server.
index.js
const { GraphQLServer } = require('graphql-yoga');
// 1
let links = [{
id: 'link-0',
url: 'www.howtographql.com',
description: 'Fullstack tutorial for GraphQL'
}];
const resolvers = {
Query: {
info: () => `This is the API of a Hackernews Clone`,
// 2
feed: () => links,
},
// 3
Link: {
id: (parent) => parent.id,
description: (parent) => parent.description,
url: (parent) => parent.url,
}
};
// 3
const server = new GraphQLServer({
typeDefs:'./schema.graphql',
resolvers,
});
server.start(() => console.log(`Server is running on http://localhost:4000`));
As you can see, I am referencing my schema file when creating the GraphQLServer. When I run the server, however, I am getting the following error:
/Users/BorisGrunwald/Desktop/programmering/Javascript/GraphQL/hackernews-node/node_modules/graphql-yoga/dist/index.js:418
throw new Error("No schema found for path: " + schemaPath);
^
My file structure:
Can anyone spot the error?
You gave the path ./schema.graphql which makes node look for the file in the directory where you run it instead of the correct location which is 'src/schema.graphql'.
So you need to change the path to:
//...
typeDefs: 'src/schema.graphql',
//...
Related
I'm using react-native-mail in my React Native app. This is my code:
const path = RNFetchBlob.fs.dirs.CacheDir + '/' + SHA1(this.fileSource.uri) + '.pdf'
const self = this;
let data = this.fileSource.uri.replace(/data:application\/pdf;base64\,/i, '');
RNFetchBlob.fs
.writeFile(path, data, 'base64')
.then(() => {
Mailer.mail({
subject: "Subject",
body: "",
recipients: [this.props.emailAddress],
attachment: {
path: path,
type: 'pdf',
name: `attachment.pdf`,
}
}, (error) => {
...
});
})
.catch(() => {
...
})
The value of path is "/data/user/0/com.<my-app-name>/cache/5cae2ea1e235873729dd158e19f3d122a1b46c73.pdf"
The value of data is TIAoxIDAgb2JqIAo8PCAKL1R5cGUgL0NhdGFsb2cgCi9QYWdlcyAyIDAgUiAKL1BhZ2VNb... (very long)
The mail() method throws the error Failed to find configured root that contains /data/user/0/com.<my-app-name>/cache/5cae2ea1e235873729dd158e19f3d122a1b46c73.pdf
Android version: 11
react-native: 0.63.4
rn-fetch-blob: 0.12.0
react-native-mail: git+https://github.com/marcinolek/react-native-mail.git
Does anyone know how I can approach this?
Try changing the file location on an external path.
With a JS script, I retrieve the stream arn from my DynamoDB table.
I will like to send this arn to serverless.yml file to use it in my function.
My serverless version:
$ serverless -v
Framework Core: 2.71.0 (standalone)
Plugin: 5.5.3
SDK: 4.3.0
Components: 3.18.1
My JS script works:
"use strict";
const AWS = require("aws-sdk");
async function run() {
const region = 'eu-west-3';
const tableName = 'dev-Connect-TrzConnect';
const dynamoDBStreams = await getDynamoDBStreams(region, tableName);
let streamArn = null;
dynamoDBStreams.Streams.forEach((stream) => {
streamArn = stream.StreamArn;
})
return streamArn;
}
const getDynamoDBStreams = async (region, tableName) => {
const dynamoStreams = new AWS.DynamoDBStreams({
region: region,
});
const params = {
TableName: tableName,
};
return dynamoStreams.listStreams(params).promise();
};
run().then((r) => console.log(r))
Now, I have no idea how to retrieve the value of streamArn variable in serverless.yml and, use it there:
functions:
createStatementFiles:
handler: lambda/statement.php
timeout: 899 # 14min 59s
layers:
- arn:aws:lambda:#{AWS::Region}:<account_id>:layer:php-73:1
role: CreateStatementFilesRole
reservedConcurrency: 10
events:
- stream:
type: dynamodb
arn: ${streamArn}
filterPatterns:
- eventName: [INSERT]
dynamodb:
NewImage:
__partitionKey:
S: [statementBalance]
I search to have something like this:
- stream:
type: dynamodb
arn: ${streamArn}
I read this documentation https://www.serverless.com/framework/docs/guides/plugins/creating-plugins but I did not understand at all how to solve my need.
Can you please help me ?
I'm trying to connect to an Azure Digital wins Instance from Visual Studio Code, using Javascript API for Azure Digital Twins.
I have ran npm install #azure/identity and npm install #azure/digital-twins-core.
I can login to Azure portal using az login from the Powershell terminal in VS Code. It finds my account and subscription and logs in.
az account get-access-token --output json returns my token.
Here's the code I'm trying to run. It should create two models in the Azure Digital Twins instance:
const { DefaultAzureCredential } = require("#azure/identity");
const { DigitalTwinsClient } = require("#azure/digital-twins-core");
const { v4 } = require("uuid");
const { inspect } = require("util");
async function main() {
const modelId = `dtmi:model_${v4()
.split("-")
.join("")};1`;
const componentId = `dtmi:component_${v4()
.split("-")
.join("")};1`;
const digitalTwinId = `digitalTwin-${v4()}`;
const temporaryComponent = {
"#id": componentId,
"#type": "Interface",
"#context": "dtmi:dtdl:context;2",
displayName: "Component1",
contents: [
{
"#type": "Property",
name: "ComponentProp1",
schema: "string"
}
]
};
const temporaryModel = {
"#id": modelId,
"#type": "Interface",
"#context": "dtmi:dtdl:context;2",
displayName: "TempModel",
contents: [
{
"#type": "Property",
name: "Prop1",
schema: "double"
},
{
"#type": "Component",
name: "Component1",
schema: componentId
}
]
};
const temporaryTwin = {
$dtId: digitalTwinId,
$metadata: {
$model: modelId
},
Prop1: 42,
Component1: {
$metadata: {},
ComponentProp1: "value1"
}
};
// AZURE_DIGITALTWINS_URL: The URL to your Azure Digital Twins instance
const url = 'https://ParADIM-ADT-Dev.api.wcus.digitaltwins.azure.net';
if (url === undefined) {
throw new Error("Required environment variable AZURE_DIGITALTWINS_URL is not set.");
}
// DefaultAzureCredential is provided by #azure/identity. It supports
// different authentication mechanisms and determines the appropriate
// credential type based of the environment it is executing in. See
// https://www.npmjs.com/package/#azure/identity for more information on
// authenticating with DefaultAzureCredential or other implementations of
// TokenCredential.
const credential = new DefaultAzureCredential();
const serviceClient = new DigitalTwinsClient(url, credential);
// Create models
const newModels = [temporaryComponent, temporaryModel];
const models = await serviceClient.createModels(newModels);
//console.log(`Created Models:`);
//console.log(inspect(models));
}
main().catch((err) => {
console.log("error code: ", err.code);
console.log("error message: ", err.message);
console.log("error stack: ", err.stack);
});
Here's the error I'm getting:
C:\Program Files\nodejs\node.exe .\index.js
error code: undefined
error message: Unexpected end of JSON input
error stack: Error: Unexpected end of JSON input
at AzureCliCredential.getToken (c:\ADTProject\node_modules\#azure\identity\dist\index.js:1529:27)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async DefaultAzureCredential.getToken (c:\ADTProject\node_modules\#azure\identity\dist\index.js:1358:25)
So, an unexpected end of JSON input. This error is coming from #azure\identity\dist\index.js which is part of the azure\identity package, so not code I wrote. The code I'm using is from a tutorial, and the JSON is compliant. Seems it's getting an error executing the getToken function.
Any help appreciated! I've hit a wall on this one!
As the code pulled from the documentation, looking into the error trace it got failed to retrieve a token from specified credentials, might be issue in how we are passing it.
Below is how we usually connect in JavaScript:
const client = new SecretClient(keyVaultUrl, new DefaultAzureCredential());
Below is the sample code to communicate with Cosmos and storage:
import { SecretClient } from '#azure/keyvault-secrets';
import { DefaultAzureCredential } from '#azure/identity';
import { CosmosClient } from '#azure/cosmos';
const keyVaultUrl = process.env('APP_KEY_VAULT_URI');
const credential = new DefaultAzureCredential();
let storageClient;
let cosmosClient;
async function configureClients() {
const kvClient = new SecretClient(keyVaultUrl, credential);
const storageUri = await client.getSecret('storageUri');
const cosmosDbConnectionString = await client.getSecret('cosmosDb');
cosmosClient = new CosmosClient(cosmosDbConnectonString);
storageClient = new BlobServiceClient(storageUri, credential);
}
For more information about environmental variables, setting keyvault refer to azure sdk blog to know about Authentication
I am trying to create a second data-access-layer for my web-app using sequelize. I get this error when i require the module 'sequelize'.
I have tried to change the node version to 4 different ones but still i do not get rid of the error.
const Sequelize = require('sequelize') // the error occur here
const sequelize = new Sequelize('sqlite::memory:')
//this is how i register the awilix container
container.register({
SQLiteDb: awilix.asValue(require('./data-access-layer-sequelize/SQLiteDb'))
})
//this is how the functions are exported
module.exports = function({ SQLiteDb }){
return {
getAllPosts: function(club, callback) {
SQLiteDb.findAll({ where: { club }, raw: true })
.then(posts => callback([], posts))
.catch(error => callback(['internalError'], null))
}
}
I am trying to connect contentful and Gatsby for a blog.
const path = require('path');
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators;
return new Promise((resolve, reject) => {
const blogPostTemplate = path.resolve('src/templates/blog-post.js');
resolve(
graphql(`
{
allContentfulBlog(limit: 100) {
edges {
node {
id
slug
}
}
}
}
`).then(result => {
if (result.errors) {
reject(result.errors);
}
result.data.allContentfulBlog.edges.forEach(edge => {
createPage({
path: edge.node.slug,
component: blogPostTemplate,
context: {
slug: edge.node.slug
}
});
});
return;
})
);
});
};
This is what I wrote in the gatsby-node.js. When I do npm run develop, it gives me an error, saying " TypeError: Cannot read property 'allContentfulBlog' of undefined." I am not sure how I should fix this. Anyone got an idea?
I ran into the same difficulties, I'm assuming you were following this youtube tutorial by khaled and try to check it out by using the default contentful Blog template like so:
Make sure you are using the CORRECT contentModelName when writing the allContentful{contentModelName} post. When using the default blog example for contentful the title shows up as "Blog Post". Just change it from "Blog Post" to "Blog" and everything should be working fine if you followed Khaled's steps and added the "new Promise" fix (which I see you already did).
Good luck!