2018-08-02 13:31:54 +00:00
|
|
|
library graphql_schema.src.schema;
|
|
|
|
|
|
|
|
import 'dart:async';
|
2018-08-03 18:59:31 +00:00
|
|
|
|
2018-08-04 19:18:53 +00:00
|
|
|
import 'package:collection/collection.dart';
|
2018-08-02 13:31:54 +00:00
|
|
|
import 'package:meta/meta.dart';
|
2018-08-03 21:07:08 +00:00
|
|
|
import 'package:source_span/source_span.dart';
|
2018-08-03 18:59:31 +00:00
|
|
|
|
2018-08-02 13:31:54 +00:00
|
|
|
part 'argument.dart';
|
2018-08-03 18:59:31 +00:00
|
|
|
|
2018-08-03 22:01:36 +00:00
|
|
|
part 'enum.dart';
|
|
|
|
|
2018-08-02 13:31:54 +00:00
|
|
|
part 'field.dart';
|
2018-08-03 18:59:31 +00:00
|
|
|
|
2018-08-02 13:31:54 +00:00
|
|
|
part 'gen.dart';
|
2018-08-03 18:59:31 +00:00
|
|
|
|
2018-08-02 13:31:54 +00:00
|
|
|
part 'object_type.dart';
|
2018-08-03 18:59:31 +00:00
|
|
|
|
2018-08-02 13:31:54 +00:00
|
|
|
part 'scalar.dart';
|
2018-08-03 18:59:31 +00:00
|
|
|
|
2018-08-02 13:31:54 +00:00
|
|
|
part 'type.dart';
|
2018-08-03 18:59:31 +00:00
|
|
|
|
2018-08-04 00:22:50 +00:00
|
|
|
part 'union.dart';
|
|
|
|
|
2018-08-02 13:31:54 +00:00
|
|
|
part 'validation_result.dart';
|
|
|
|
|
|
|
|
class GraphQLSchema {
|
2018-08-04 19:18:53 +00:00
|
|
|
final GraphQLObjectType queryType;
|
|
|
|
final GraphQLObjectType mutationType;
|
|
|
|
final GraphQLObjectType subscriptionType;
|
2018-08-02 13:31:54 +00:00
|
|
|
|
2018-08-04 19:18:53 +00:00
|
|
|
GraphQLSchema({this.queryType, this.mutationType, this.subscriptionType});
|
2018-08-02 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GraphQLSchema graphQLSchema(
|
2018-08-04 19:18:53 +00:00
|
|
|
{@required GraphQLObjectType queryType,
|
|
|
|
GraphQLObjectType mutationType,
|
|
|
|
GraphQLObjectType subscriptionType}) =>
|
2018-08-03 18:59:31 +00:00
|
|
|
new GraphQLSchema(
|
2018-08-04 19:18:53 +00:00
|
|
|
queryType: queryType,
|
|
|
|
mutationType: mutationType,
|
|
|
|
subscriptionType: subscriptionType);
|
2018-08-02 15:17:14 +00:00
|
|
|
|
|
|
|
/// A default resolver that always returns `null`.
|
|
|
|
resolveToNull(_, __) => null;
|
2018-08-02 18:33:50 +00:00
|
|
|
|
2018-08-03 21:07:08 +00:00
|
|
|
/// An error that occurs during execution of a GraphQL query.
|
|
|
|
class GraphQLException implements Exception {
|
|
|
|
final List<GraphQLExceptionError> errors;
|
|
|
|
|
|
|
|
GraphQLException(this.errors);
|
|
|
|
|
|
|
|
factory GraphQLException.fromMessage(String message) {
|
|
|
|
return new GraphQLException([
|
|
|
|
new GraphQLExceptionError(message),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
factory GraphQLException.fromSourceSpan(String message, FileSpan span) {
|
|
|
|
return new GraphQLException([
|
|
|
|
new GraphQLExceptionError(
|
|
|
|
message,
|
|
|
|
locations: [
|
|
|
|
new GraphExceptionErrorLocation.fromSourceLocation(span.start),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, List<Map<String, dynamic>>> toJson() {
|
|
|
|
return {
|
|
|
|
'errors': errors.map((e) => e.toJson()).toList(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class GraphQLExceptionError {
|
|
|
|
final String message;
|
|
|
|
final List<GraphExceptionErrorLocation> locations;
|
|
|
|
|
|
|
|
GraphQLExceptionError(this.message, {this.locations: const []});
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
var out = <String, dynamic>{'message': message};
|
|
|
|
if (locations?.isNotEmpty == true) {
|
|
|
|
out['locations'] = locations.map((l) => l.toJson()).toList();
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class GraphExceptionErrorLocation {
|
|
|
|
final int line;
|
|
|
|
final int column;
|
|
|
|
|
|
|
|
GraphExceptionErrorLocation(this.line, this.column);
|
|
|
|
|
|
|
|
factory GraphExceptionErrorLocation.fromSourceLocation(
|
|
|
|
SourceLocation location) {
|
|
|
|
return new GraphExceptionErrorLocation(location.line, location.column);
|
|
|
|
}
|
2018-08-02 18:33:50 +00:00
|
|
|
|
2018-08-03 21:07:08 +00:00
|
|
|
Map<String, int> toJson() {
|
|
|
|
return {'line': line, 'column': column};
|
|
|
|
}
|
2018-08-02 18:33:50 +00:00
|
|
|
}
|
2018-08-03 18:59:31 +00:00
|
|
|
|
2018-08-04 00:12:23 +00:00
|
|
|
typedef GraphQLType _GraphDocumentationTypeProvider();
|
|
|
|
|
2018-08-03 18:59:31 +00:00
|
|
|
/// A metadata annotation used to provide documentation to `package:graphql_server`.
|
|
|
|
class GraphQLDocumentation {
|
|
|
|
final String description;
|
2018-08-03 21:51:30 +00:00
|
|
|
final String deprecationReason;
|
2018-08-04 00:12:23 +00:00
|
|
|
final _GraphDocumentationTypeProvider type;
|
2018-08-03 18:59:31 +00:00
|
|
|
|
2018-08-04 00:12:23 +00:00
|
|
|
const GraphQLDocumentation(
|
|
|
|
{this.description, this.deprecationReason, GraphQLType this.type()});
|
2018-08-03 18:59:31 +00:00
|
|
|
}
|