-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better handling for maps including the ability to wrap the Map.Entry …
…classes to control the naming of the key and value GraphQL fields. Added the GraphQLOverrideName annotation that tells our custom TypeInfoGenerator to not append 'Input' and 'Scalar' to InputTypes and Scalar types respectively.
- Loading branch information
blevine
committed
Oct 5, 2024
1 parent
7bc60db
commit 366f0a7
Showing
22 changed files
with
1,039 additions
and
102 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
17 changes: 17 additions & 0 deletions
17
graphql/src/main/java/net/brianlevine/keycloak/graphql/annotations/GraphQLMapAlias.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,17 @@ | ||
package net.brianlevine.keycloak.graphql.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* TBD: Notional. Maybe use this to change the field names for Map.Entry objects. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface GraphQLMapAlias { | ||
String keyAlias() default ""; | ||
String valueAlias() default ""; | ||
} | ||
|
15 changes: 15 additions & 0 deletions
15
...l/src/main/java/net/brianlevine/keycloak/graphql/annotations/GraphQLOverrideTypeName.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,15 @@ | ||
package net.brianlevine.keycloak.graphql.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* For InputTypes and Scalars. Classes annotated with GraphQLOverrideTypeName will not have a suffix ('Input' for | ||
* InputTypes and 'Scalar' for Scalar types) appended. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface GraphQLOverrideTypeName { | ||
} |
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
26 changes: 26 additions & 0 deletions
26
graphql/src/main/java/net/brianlevine/keycloak/graphql/types/AttributeMap.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,26 @@ | ||
package net.brianlevine.keycloak.graphql.types; | ||
|
||
import net.brianlevine.keycloak.graphql.util.PagedMap; | ||
|
||
import java.util.Map; | ||
|
||
public class AttributeMap extends PagedMap<String, String, AttributeMap.Entry> { | ||
|
||
public AttributeMap(Map<String, String> map, int start, int limit) { | ||
super(map, start, limit, AttributeMap.Entry.class); | ||
} | ||
|
||
public static class Entry extends PagedMap.DelegatingEntry<String, String> implements Map.Entry<String, String> { | ||
public Entry(Map.Entry<String, String> delegate) { | ||
super(delegate); | ||
} | ||
|
||
public String getName() { | ||
return delegate.getKey(); | ||
} | ||
|
||
public String getValue() { | ||
return delegate.getValue(); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
graphql/src/main/java/net/brianlevine/keycloak/graphql/types/ClientPolicyExecutorType.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,44 @@ | ||
package net.brianlevine.keycloak.graphql.types; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.leangen.graphql.annotations.types.GraphQLType; | ||
import org.keycloak.representations.idm.ClientPolicyExecutorRepresentation; | ||
|
||
import java.util.Objects; | ||
|
||
@GraphQLType | ||
@SuppressWarnings("unused") | ||
public class ClientPolicyExecutorType { | ||
private final ClientPolicyExecutorRepresentation delegate; | ||
|
||
public ClientPolicyExecutorType(ClientPolicyExecutorRepresentation clientPolicyExecutorRepresentation) { | ||
this.delegate = clientPolicyExecutorRepresentation; | ||
} | ||
|
||
public String getExecutorProviderId() { | ||
return delegate.getExecutorProviderId(); | ||
} | ||
|
||
public void setExecutorProviderId(String providerId) { | ||
delegate.setExecutorProviderId(providerId); | ||
} | ||
|
||
public JsonNode getConfiguration() { | ||
return delegate.getConfiguration(); | ||
} | ||
|
||
public void setConfiguration(JsonNode configuration) { | ||
delegate.setConfiguration(configuration); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (delegate.getClass() != o.getClass()) return false; | ||
return delegate.equals(o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return delegate.hashCode(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
graphql/src/main/java/net/brianlevine/keycloak/graphql/types/ClientProfileType.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,62 @@ | ||
package net.brianlevine.keycloak.graphql.types; | ||
|
||
import io.leangen.graphql.annotations.GraphQLArgument; | ||
import io.leangen.graphql.annotations.types.GraphQLType; | ||
import net.brianlevine.keycloak.graphql.util.Page; | ||
import org.keycloak.representations.idm.ClientPolicyExecutorRepresentation; | ||
import org.keycloak.representations.idm.ClientProfileRepresentation; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@GraphQLType | ||
@SuppressWarnings("unused") | ||
public class ClientProfileType { | ||
private final ClientProfileRepresentation delegate; | ||
|
||
public ClientProfileType(ClientProfileRepresentation clientProfileRepresentation) { | ||
this.delegate = clientProfileRepresentation; | ||
} | ||
|
||
public String getName() { | ||
return delegate.getName(); | ||
} | ||
|
||
public void setName(String name) { | ||
delegate.setName(name); | ||
} | ||
|
||
public String getDescription() { | ||
return delegate.getDescription(); | ||
} | ||
|
||
public void setDescription(String description) { | ||
delegate.setDescription(description); | ||
} | ||
|
||
public Page<ClientPolicyExecutorType> getExecutors(@GraphQLArgument(defaultValue = "0")int start, @GraphQLArgument(defaultValue = "100")int limit) { | ||
List<ClientPolicyExecutorRepresentation> executors = delegate.getExecutors(); | ||
List<ClientPolicyExecutorType> ets = executors.stream() | ||
.skip(start) | ||
.limit(limit) | ||
.map(ClientPolicyExecutorType::new) | ||
.toList(); | ||
|
||
return new Page<>(executors.size(), limit, ets); | ||
} | ||
|
||
public void setExecutors(List<ClientPolicyExecutorRepresentation> executors) { | ||
delegate.setExecutors(executors); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (delegate.getClass() != o.getClass()) return false; | ||
return delegate.equals(o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return delegate.hashCode(); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
graphql/src/main/java/net/brianlevine/keycloak/graphql/types/ClientScopeType.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,85 @@ | ||
package net.brianlevine.keycloak.graphql.types; | ||
|
||
import io.leangen.graphql.annotations.GraphQLArgument; | ||
import io.leangen.graphql.annotations.types.GraphQLType; | ||
import net.brianlevine.keycloak.graphql.util.Page; | ||
import org.keycloak.representations.idm.ClientScopeRepresentation; | ||
import org.keycloak.representations.idm.ProtocolMapperRepresentation; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@GraphQLType | ||
@SuppressWarnings("unused") | ||
public class ClientScopeType { | ||
private final ClientScopeRepresentation delegate; | ||
|
||
public ClientScopeType(ClientScopeRepresentation clientScopeRepresentation) { | ||
this.delegate = clientScopeRepresentation; | ||
} | ||
|
||
public String getId() { | ||
return delegate.getId(); | ||
} | ||
|
||
public void setId(String id) { | ||
delegate.setId(id); | ||
} | ||
|
||
public String getName() { | ||
return delegate.getName(); | ||
} | ||
|
||
public void setName(String name) { | ||
delegate.setName(name); | ||
} | ||
|
||
public String getDescription() { | ||
return delegate.getDescription(); | ||
} | ||
|
||
public void setDescription(String description) { | ||
delegate.setDescription(description); | ||
} | ||
|
||
public Page<ProtocolMapperType> getProtocolMappers(@GraphQLArgument(defaultValue = "0")int start, @GraphQLArgument(defaultValue = "100")int limit) { | ||
List<ProtocolMapperType> pms = delegate.getProtocolMappers().stream() | ||
.skip(start) | ||
.limit(limit) | ||
.map(ProtocolMapperType::new) | ||
.toList(); | ||
|
||
return new Page<>(pms.size(), limit, pms); | ||
} | ||
|
||
public void setProtocolMappers(List<ProtocolMapperRepresentation> protocolMappers) { | ||
delegate.setProtocolMappers(protocolMappers); | ||
} | ||
|
||
public String getProtocol() { | ||
return delegate.getProtocol(); | ||
} | ||
|
||
public void setProtocol(String protocol) { | ||
delegate.setProtocol(protocol); | ||
} | ||
|
||
public AttributeMap getAttributes(@GraphQLArgument(defaultValue = "0")int start, @GraphQLArgument(defaultValue = "100")int limit) { | ||
return new AttributeMap(delegate.getAttributes(), start, limit); | ||
} | ||
|
||
public void setAttributes(Map<String, String> attributes) { | ||
delegate.setAttributes(attributes); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (!(o instanceof ClientScopeRepresentation)) return false; | ||
return delegate.equals(o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return delegate.hashCode(); | ||
} | ||
} |
Oops, something went wrong.