Invariant violation when using react apollo hooks alongside query components - graphql

I'm beginning our migration from Apollo Client 2.x to 3.x beta, and I'm having trouble using both the apollo hooks and the now deprecated query/mutation components.
I'm using the packages:
#apollo/client: 3.0.0-beta.4
#apollo/react-components: 3.1.3
Using the apollo hooks works fine in this case, but using the query component, I get the following error:
Invariant Violation
Could not find "client" in the context or passed in as an option.
Wrap the root component in an , or pass an ApolloClient instance in via options.
I've created a codesandbox that shows this issue here:
https://codesandbox.io/s/react-example-9p9ym
I think the issue is with the source of the ApolloProvider I'm using, but not sure which package to get that from if I want to use the new beta, while still using the query components.

You should import ApolloProvider from the same package as the component or hook that's using it. That's because the context provided by ApolloProvider needs to be the same as the context being used by the component or hook. if you use different packages, the context object will be different.
The react-apollo package exports all three: ApolloProvider, Query and useQuery. If you use that package, you can use the ApolloProvider with both Query and useQuery. #apollo/client, however, only exports ApolloProvider and useQuery. That's because the graphql HOC and the render prop components have been deprecated. If you insist on using both Query and useQuery, you have to import Query from another package, like #apollo/react-components and add its ApolloProvider as well:
import {
ApolloProvider as ApolloProvider2,
Query,
} from '#apollo/react-components'
import {
ApolloProvider,
ApolloClient,
HttpLink,
InMemoryCache,
useQuery,
gql,
} from '#apollo/client'
<ApolloProvider2 client={client}>
<ApolloProvider client={client}>
<App/>
</ApolloProvider>
</ApolloProvider2>
Notice that you can import gql directly from apollo#client as well.

Related

How to disable management context access log in Spring Boot using undertow

I'm using Spring Boot 2.2.4 with embedded Undertow.
I've enabled the access log using server.underdow.accesslog.enabled=true and everything works as expected.
I'm utilizing the actuator endpoints on a different port which sets up a child context. I do not want requests to the actuator to be logged. Currently they automatically go to management_access.log where access. is the prefix of my main access log.
Any ideas on how to disable that access log? I know Spring is creating a separate WebServer via Factory for the actuator context, but I haven't found a way to customize the factory.
I found my own answer (spent way too much time doing it).
It's a little bit of a hack, but it works:
New configuration class: foo.ManagementConfig
package foo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
#ManagementContextConfiguration
public class ManagementConfig {
#Bean
WebServerFactoryCustomizer<UndertowServletWebServerFactory> actuatorCustomizer(#Value("${management.server.port}") int managementPort) {
return factory -> {
if (managementPort == factory.getPort()) {
factory.setAccessLogEnabled(false);
}
};
}
}
Created resources/META-INF/spring.factories so that it gets picked up by the ManagementContext:
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration=foo.ManagementConfig
The part that's a bit of a hack is the if statement. It would have been great if it applied only to the management context, but for some reason it's trying to apply to both. With the if statement, it just doesn't do anything for the primary context.
This would have unintended consequences if management.server.port was undefined or if it was the same as the primary context.

Does MaterialModule include HttpModule?

Does MaterialModule in Angular Material 2 include Http providers by default?
I have created a service that injects Http from #angular/http. If I omit to import HttpModule in the main AppModule, there is no error and everything works as expected. If on the contrary, I remove the import of MaterialModule, then I get the error that there is no provider for Http.
Since I import the whole MaterialModule, I can see that this is due to the automatic import of MdIconModule. It uses HttpModule internally in order to fetch Material Design icons.

Apache Felix: inherit import package org.osgi.service.cm

I have one bundle which has Import-Package org.osgi.service.cm. In this bundle there is only an interface ConfigurationInterface, that declares a couple of methods, one throws an org.osgi.service.cm.ConfigurationException. This bundle exports only its own package, lets say com.foo.bar.configuration.
Then I have other API bundles that have an interface for the service, ServiceInterface, that extends ConfigurationInterface, so they are importing the package com.foo.bar.configuration. Obviously there are also implementations bundle for these api that implement ServiceInterface, so they are importing org.osgi.service.cm because every implementations need to have the method that throws an org.osgi.service.cm.ConfigurationException.
Everything is working fine, the problems come out when I declare these services as optional, because when they are not available the framework tries to instantiate a proxy from the interface and I get a java.lang.ClassNotFoundException: org.osgi.service.cm.ConfigurationException. The framework suggests to add an import for 'org.osgi.service.cm' to the API bundle.
Is there a way to make this import available from the configuration bundle so that it is not necessary to add the import to every API?

You do not have an implicit Application in scope: PlayFramework with Oracle

Getting following error when trying to access oracle DataSource using play framework:
sbt.PlayExceptions$CompilationException: Compilation error[You do not have an implicit Application in scope. If you want to bring
the current running Application into context, just add import play.api.Play.current]
build.properties:
sbt.version=0.12.2
db.default.driver=oracle.jdbc.driver.OracleDriver
db.default.url="jdbc:oracle:thin:#(.....basic))))"
db.default.user="username"
db.default.pass="passowrd"
Controller Application.scala is as follows:
package controllers
import play.api._
import play.api.mvc._
import play.api.db._
object Application extends Controller {
val d = DB.getDataSource();
def index = Action { request => Ok("something") }
}
What is causing this issue. Everything looks correct to me.
FYI. play! 2.1.4 (using Java 1.6.0_24 and Scala 2.10.0)
-Thanks
The error message is actually telling you what to do: You do not have an implicit Application in scope. If you want to bring the current running Application into context, just add import play.api.Play.current.
import play.api.Play.current
This is what the getDataSource method look like:
def getDataSource(name: String = "default")(implicit app: Application): DataSource = app.plugin[DBPlugin].map(_.api.getDataSource(name)).getOrElse(error)
As you can see it takes an implicit Application in the second argument list and the compiler is looking for an implicitly declared Application which can be found in the import.

liferay event listener

i have some hard task, i need to change some part of my project using jboss portal 2.7.2 into liferay. Ofc less change better but all jboss portal must disappear. I need 2 replace classes below. So my question is how using liferay portal implements(or not(if already exist)) listener which will know when someone is trying 2 log in. Make login possible without reloading etc. Ofc it was nice if there was some pro eventlistener in liferay which can recognise other events not only logging but i will be glad for all help. 4 the rest of this class will be nice if someone know replacment 4 them in liferay.
import org.jboss.portal.api.event.PortalEvent;
import org.jboss.portal.api.event.PortalEventContext;
import org.jboss.portal.api.event.PortalEventListener;
import org.jboss.portal.api.session.PortalSession;
import org.jboss.portal.api.user.event.UserAuthenticationEvent;
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.NoSuchUserException;
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.UserModule;
import org.jboss.portal.identity.UserProfileModule;
Liferay has similar approache. Create a Hook and add properties like http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/extending-and-overriding-%3Cem%3Eportal-properties%3C-e-1
With the properties you can specificy wich class schould be call by the portal events:
login.events.post=my.package.AfterLoginHandler
with the same approche you can listen to creating/changes/removes of entities:
value.object.listener.com.liferay.portal.model.User=my.package.UserListener
value.object.listener.com.liferay.portal.model.Layout=my.package.LayoutListener
...
Liferay does allow adding handlers to login events. More information can be found # http://www.learnercorner.in/topics?showTopic=16001

Resources