| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| package graphql.schema.idl; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import graphql.GraphQLError; | ||
| import graphql.PublicApi; | ||
| import graphql.language.DirectiveDefinition; | ||
| import graphql.language.EnumTypeExtensionDefinition; | ||
| import graphql.language.InputObjectTypeExtensionDefinition; | ||
| import graphql.language.InterfaceTypeExtensionDefinition; | ||
| import graphql.language.ObjectTypeExtensionDefinition; | ||
| import graphql.language.SDLDefinition; | ||
| import graphql.language.ScalarTypeDefinition; | ||
| import graphql.language.ScalarTypeExtensionDefinition; | ||
| import graphql.language.SchemaExtensionDefinition; | ||
| import graphql.language.TypeDefinition; | ||
| import graphql.language.UnionTypeExtensionDefinition; | ||
| import graphql.schema.idl.errors.SchemaProblem; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
||
| import static com.google.common.collect.ImmutableMap.copyOf; | ||
|
|
||
| /** | ||
| * A {@link ImmutableTypeDefinitionRegistry} contains an immutable set of type definitions that come from compiling | ||
| * a graphql schema definition file via {@link SchemaParser#parse(String)} and is more performant because it | ||
| * uses {@link ImmutableMap} structures. | ||
| */ | ||
| @SuppressWarnings("rawtypes") | ||
| @PublicApi | ||
| @NullMarked | ||
| public class ImmutableTypeDefinitionRegistry extends TypeDefinitionRegistry { | ||
| ImmutableTypeDefinitionRegistry(TypeDefinitionRegistry registry) { | ||
| super( | ||
| copyOf(registry.objectTypeExtensions), | ||
| copyOf(registry.interfaceTypeExtensions), | ||
| copyOf(registry.unionTypeExtensions), | ||
| copyOf(registry.enumTypeExtensions), | ||
| copyOf(registry.scalarTypeExtensions), | ||
| copyOf(registry.inputObjectTypeExtensions), | ||
| copyOf(registry.types), | ||
| copyOf(registry.scalars()), // has an extra side effect | ||
| copyOf(registry.directiveDefinitions), | ||
| ImmutableList.copyOf(registry.schemaExtensionDefinitions), | ||
| registry.schema, | ||
| registry.schemaParseOrder | ||
| ); | ||
| } | ||
|
|
||
| private UnsupportedOperationException unsupportedOperationException() { | ||
| return new UnsupportedOperationException("The TypeDefinitionRegistry is in read only mode"); | ||
| } | ||
|
|
||
| @Override | ||
| public TypeDefinitionRegistry merge(TypeDefinitionRegistry typeRegistry) throws SchemaProblem { | ||
| throw unsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<GraphQLError> addAll(Collection<SDLDefinition> definitions) { | ||
| throw unsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<GraphQLError> add(SDLDefinition definition) { | ||
| throw unsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public void remove(SDLDefinition definition) { | ||
| throw unsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public void remove(String key, SDLDefinition definition) { | ||
| throw unsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, TypeDefinition> types() { | ||
| return types; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, ScalarTypeDefinition> scalars() { | ||
| return scalarTypes; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, List<ObjectTypeExtensionDefinition>> objectTypeExtensions() { | ||
| return objectTypeExtensions; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, List<InterfaceTypeExtensionDefinition>> interfaceTypeExtensions() { | ||
| return interfaceTypeExtensions; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, List<UnionTypeExtensionDefinition>> unionTypeExtensions() { | ||
| return unionTypeExtensions; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, List<EnumTypeExtensionDefinition>> enumTypeExtensions() { | ||
| return enumTypeExtensions; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, List<ScalarTypeExtensionDefinition>> scalarTypeExtensions() { | ||
| return scalarTypeExtensions; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, List<InputObjectTypeExtensionDefinition>> inputObjectTypeExtensions() { | ||
| return inputObjectTypeExtensions; | ||
| } | ||
|
|
||
| @Override | ||
| public List<SchemaExtensionDefinition> getSchemaExtensionDefinitions() { | ||
| return schemaExtensionDefinitions; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, DirectiveDefinition> getDirectiveDefinitions() { | ||
| return directiveDefinitions; | ||
| } | ||
| } | ||
|
Comment thread
Copy link
Copy Markdown
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityNo copies made for these read only methods
Sorry, something went wrong.
All reactions
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -103,17 +103,19 @@ public GraphQLSchema makeExecutableSchema(Options options, TypeDefinitionRegistr | |
|
|
||
| schemaGeneratorHelper.addDirectivesIncludedByDefault(typeRegistryCopy); | ||
|
|
||
| List<GraphQLError> errors = typeChecker.checkTypeRegistry(typeRegistryCopy, wiring); | ||
| // by making it read only all the traversal and checks run faster | ||
| ImmutableTypeDefinitionRegistry fasterImmutableRegistry = typeRegistryCopy.readOnly(); | ||
| List<GraphQLError> errors = typeChecker.checkTypeRegistry(fasterImmutableRegistry, wiring); | ||
|
Comment thread
Copy link
Copy Markdown
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis is where the performance gains will be made
Sorry, something went wrong.
All reactions
|
||
| if (!errors.isEmpty()) { | ||
| throw new SchemaProblem(errors); | ||
| } | ||
|
|
||
| Map<String, OperationTypeDefinition> operationTypeDefinitions = SchemaExtensionsChecker.gatherOperationDefs(typeRegistry); | ||
| Map<String, OperationTypeDefinition> operationTypeDefinitions = SchemaExtensionsChecker.gatherOperationDefs(fasterImmutableRegistry); | ||
|
|
||
| return makeExecutableSchemaImpl(typeRegistryCopy, wiring, operationTypeDefinitions, options); | ||
| return makeExecutableSchemaImpl(fasterImmutableRegistry, wiring, operationTypeDefinitions, options); | ||
| } | ||
|
|
||
| private GraphQLSchema makeExecutableSchemaImpl(TypeDefinitionRegistry typeRegistry, | ||
| private GraphQLSchema makeExecutableSchemaImpl(ImmutableTypeDefinitionRegistry typeRegistry, | ||
| RuntimeWiring wiring, | ||
| Map<String, OperationTypeDefinition> operationTypeDefinitions, | ||
| Options options) { | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -111,7 +111,7 @@ public class SchemaGeneratorHelper { | |
| * it gives us helper functions | ||
| */ | ||
| static class BuildContext { | ||
| private final TypeDefinitionRegistry typeRegistry; | ||
| private final ImmutableTypeDefinitionRegistry typeRegistry; | ||
| private final RuntimeWiring wiring; | ||
|
Comment thread
Copy link
Copy Markdown
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI made this use the type just to be more explicit but I didnt change it every where it gets used
Sorry, something went wrong.
All reactions
|
||
| private final Deque<String> typeStack = new ArrayDeque<>(); | ||
|
|
||
| Expand All | @@ -123,7 +123,7 @@ static class BuildContext { | |
| public final SchemaGenerator.Options options; | ||
| public boolean directiveWiringRequired; | ||
|
|
||
| BuildContext(TypeDefinitionRegistry typeRegistry, RuntimeWiring wiring, Map<String, OperationTypeDefinition> operationTypeDefinitions, SchemaGenerator.Options options) { | ||
| BuildContext(ImmutableTypeDefinitionRegistry typeRegistry, RuntimeWiring wiring, Map<String, OperationTypeDefinition> operationTypeDefinitions, SchemaGenerator.Options options) { | ||
| this.typeRegistry = typeRegistry; | ||
| this.wiring = wiring; | ||
| this.codeRegistry = GraphQLCodeRegistry.newCodeRegistry(wiring.getCodeRegistry()); | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -52,7 +52,7 @@ | |
| @Internal | ||
| public class SchemaTypeChecker { | ||
|
|
||
| public List<GraphQLError> checkTypeRegistry(TypeDefinitionRegistry typeRegistry, RuntimeWiring wiring) throws SchemaProblem { | ||
| public List<GraphQLError> checkTypeRegistry(ImmutableTypeDefinitionRegistry typeRegistry, RuntimeWiring wiring) throws SchemaProblem { | ||
|
Comment thread
Copy link
Copy Markdown
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI made this use the type just to be more explicit but I didnt change it every where it gets used
Sorry, something went wrong.
All reactions
|
||
| List<GraphQLError> errors = new ArrayList<>(); | ||
| checkForMissingTypes(errors, typeRegistry); | ||
|
|
||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAll the mutative methods are unsupported
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.