-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to io.micrometer:context-propagation library
See gh-459
- Loading branch information
1 parent
f583eb3
commit f680892
Showing
32 changed files
with
415 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...g-graphql/src/main/java/org/springframework/graphql/execution/GraphQlContextAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2002-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.graphql.execution; | ||
|
||
|
||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
import graphql.GraphQLContext; | ||
import io.micrometer.context.ContextAccessor; | ||
|
||
/** | ||
* {@code ContextAccessor} that enables support for reading and writing values | ||
* to and from a {@link GraphQLContext}. This accessor is automatically | ||
* registered via {@link java.util.ServiceLoader}. | ||
* | ||
* @author Rossen Stoyanchev | ||
* @since 1.1.0 | ||
*/ | ||
public class GraphQlContextAccessor implements ContextAccessor<GraphQLContext, GraphQLContext> { | ||
|
||
@Override | ||
public boolean canReadFrom(Class<?> contextType) { | ||
return GraphQLContext.class.equals(contextType); | ||
} | ||
|
||
@Override | ||
public void readValues(GraphQLContext context, Predicate<Object> keyPredicate, Map<Object, Object> readValues) { | ||
context.stream().forEach(entry -> { | ||
if (keyPredicate.test(entry.getKey())) { | ||
readValues.put(entry.getKey(), entry.getValue()); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public <T> T readValue(GraphQLContext context, Object key) { | ||
return context.get(key); | ||
} | ||
|
||
@Override | ||
public boolean canWriteTo(Class<?> contextType) { | ||
return GraphQLContext.class.equals(contextType); | ||
} | ||
|
||
@Override | ||
public GraphQLContext writeValues(Map<Object, Object> valuesToWrite, GraphQLContext targetContext) { | ||
return targetContext.putAll(valuesToWrite); | ||
} | ||
|
||
} |
Oops, something went wrong.