Skip to content
New issue

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

Allow mutation and subscription operations #41

Merged
merged 5 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gql_code_builder/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ Reference typeRef(
Map<String, Reference> typeMap = defaultTypeMap,
]) =>
_listOrNot(type, typeMap);

const defaultRootTypes = {
OperationType.query: "Query",
OperationType.mutation: "Mutation",
OperationType.subscription: "Subscription"
};
22 changes: 21 additions & 1 deletion gql_code_builder/lib/src/operation/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,29 @@ List<Class> _buildOperationDataClasses(
doc,
schema,
schemaUrl,
"Query",
_operationType(
schema,
op,
),
);

String _operationType(
DocumentNode schema,
OperationDefinitionNode op,
) {
final schemaDefs = schema.definitions.whereType<SchemaDefinitionNode>();
klavs marked this conversation as resolved.
Show resolved Hide resolved

if (schemaDefs.isEmpty) return defaultRootTypes[op.type];

return schemaDefs.first.operationTypes
.firstWhere(
(opType) => opType.operation == op.type,
)
.type
.name
.value;
}

List<Class> _buildSelectionSetDataClasses(
String name,
SelectionSetNode selSet,
Expand Down