I'm trying to create a package that exports functionality using useQuery
However I get the following error:
Could not find "client" in the context or passed in as an option. Wrap the root component in an <ApolloProvider>, or pass an ApolloClient instance in via options.
This is even with simplest possible example which just exports useQuery (obvs real code does more than this)
I know my code is ok otherwise as if I import useQuery using
import { useQuery } from '#apollo/react-hooks'
it works fine
simple example is here..
https://github.com/gilesbradshaw/use-query
The hook and the ApolloProvider used should be from the same module, otherwise the context used by the hook will be different than what is provided by the ApolloProvider. You should export ApolloProvider in your package in addition to the hook, and then make sure you import it from your package whereever you're using the hook.
Related
I'm working on my first query module for Memgraph. I'm trying to find the best approach.
I have a query module that depends on a local submodule (firstone):
import firstone
import mgp
import importlib
#mgp.read_proc
def procedure(context...):
importlib.reload(firstone)
firstone.call()
If I get it correctly, if firstone module changes, the procedure is still using the previous code. How can I reload the Python query module during development?
You can use the use mg.load to load or reload the given module. The correct syntax is CALL mg.load("py_example");. After loading the module, all dependent Python's submodules that are imported will also be reloaded. The official documentation can be found on Memgraph site.
Within my Cypress tests I would like to use the endpoints that I generate from our swagger documentation. However, these endpoints use a custom Axios client, that uses Redux and a ton of other dependencies. I can mock this client, but only by using:
import * as CustomAxios from "libs/custom";
cy.stub(CustomAxios, "customAxios");
However, within this file "custom.ts", I have the following code:
export const customAxios = createCustomAxiosClient()
It seems I cannot mock this file, without importing the file, and calling this method (which creates errors). Does anyone have an idea how I can mock this customAxios client without having the createCustomAxiosClient() method being called (which I cannot remove).
I tried reading the documentation and other questions, but I could not find any answers to my specific case.
I have a layer where the path of node_modules is nodejs/node14/node_modules.
Using that layer, and I try to import a package in a Lambda function, say 'aws-cloudfront-sign', like this:
import cfsign from 'aws-cloudfront-sign'
I got error message
Cannot find package 'aws-cloudfront-sign' imported from /var/task/signer.js\nDid you mean to import aws-cloudfront-sign/lib/cloudfrontUtil.js?
But if I import the package like this:
import cfsign from '/opt/nodejs/node14/node_modules/aws-cloudfront-sign/lib/cloudfrontUtil.js'
It succeeds.
Do you know why? How could I import the package correctly?
This appears to be a bug. It is occurring with layers and the SDK. There are are a number of similar open issues on Github:
Nodejs Lambda: Cannot find package 'aws-sdk'
Cannot find package when using ES Module and Lambda Layer
ES6 imports don't work in #aws-sdk/client-iotsitewise
As you have worked out, the only workaround at present seems to be the use of absolute paths. E.g.:
import { DynamoDB } from 'aws-sdk;'
fails, whereas
import AWS from '/var/runtime/node_modules/aws-sdk/lib/aws.js';
const { DynamoDB } = AWS;
will work.
I suggest you add your voice to an existing open issue to help ensure it gets attention.
To make an http call using python my way was to use requests.
But requests is not installed in lambda context. Using import requests resulted in module is not found error.
The other way is to use the provided lib from botocore.vendored import requests. But this lib is deprecated by AWS.
I want to avoid to package dependencies within my lambda zip file.
What is the smartest solution to make a REST call in python based lambda?
Solution 1)
Since from botocore.vendored import requests is deprecated the recomended way is to install your dependencies.
$ pip install requests
import requests
response = requests.get('https://...')
See also. https://aws.amazon.com/de/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/
But you have to take care for packaging the dependencies within your lambda zip.
Solution 2)
My preferred solution is to use urllib. It's within your lambda execution context.
https://repl.it/#SmaMa/DutifulChocolateApplicationprogrammer
import urllib.request
import json
res = urllib.request.urlopen(urllib.request.Request(
url='http://asdfast.beobit.net/api/',
headers={'Accept': 'application/json'},
method='GET'),
timeout=5)
print(res.status)
print(res.reason)
print(json.loads(res.read()))
Solution 3)
Using http.client, it's also within your lambda execution context.
https://repl.it/#SmaMa/ExoticUnsightlyAstrophysics
import http.client
connection = http.client.HTTPSConnection('fakerestapi.azurewebsites.net')
connection.request('GET', '/api/Books')
response = connection.getresponse()
print(response.read().decode())
I am using React-Bootstrap version 1.0.0-beta.10.
Whenever I want to use a component, for example Alert, I will get three import options from the IDE to choose from:
"react-bootstrap"
"react-bootstrap/Alert"
"react-bootstrap/es/Alert"
Which of them should I use and why?
Yes. We have multiple options to import a component.
When importing directly from react-bootstrap you need to import as,
import {Alert} from `react-bootstrap`;
Because Alert component is exported as named export.
If you expand the react-bootstrap folder from node_modules folder, you will see multiple folders and files.
The files directly available in react-bootstrap folder are based on ES5.
When I say based on ES5 means, the required package for this component are imported like this,
var _extends2 = _interopRequireDefault(require("#babel/runtime/helpers/extends"));
and you can import component as,
import Alert from `react-bootstrap/Alert`;
Because Alert component is exported as default export.
The files available in es folder are based on ES6.
When I say based on ES6 means, the required package for this component are imported like this,
import _extends from "#babel/runtime/helpers/esm/extends";
and you can import component as,
import Alert from `react-bootstrap/es/Alert`;
Because Alert component is exported as default export.
You must have to change your codebase.
react-bootstrap doesn't have a default export, so the default import syntax cannot be used in this case.
You can do the following though:
import * as ReactBootstrap from 'react-bootstrap';
And then, you can use the Alert component.