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

Replace artemis with graphql_codegen #1788

Open
wants to merge 1 commit into
base: upgrade-flutter-to-3.22
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ runConfigurations.xml

# Generated code
lib/build_config/build_config.dart
lib/graphql/graphql_api.dart
lib/graphql/graphql_api.graphql.dart
lib/graphql/graphql_api.graphql.g.dart

lib/graphql_gen
lib/proto
/lib/l10n/translations.g.dart

Expand Down
2 changes: 1 addition & 1 deletion frontend/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include: package:lints/recommended.yaml
analyzer:
exclude:
- build/**
- lib/graphql/graphql_api*.dart
- lib/graphql_gen/**
- lib/build_config/build_config.dart
- lib/proto/*.dart
- pubs/**
Expand Down
28 changes: 12 additions & 16 deletions frontend/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ targets:
sources:
- $package$
- lib/$lib$
- graphql_queries/**
- schema.graphql
- "**.graphql"
- proto/**
- lib/build_config/build_config.yaml
- assets/l10n/*
Expand All @@ -26,21 +25,18 @@ targets:
out_dir: "lib/proto"
grpc: false
precompile_protoc_plugin: true
artemis:
graphql_codegen:
options:
schema_mapping:
- schema: schema.graphql
queries_glob: graphql_queries/**.graphql
output: lib/graphql/graphql_api.dart
scalar_mapping:
- graphql_type: Long
dart_type: int
- graphql_type: Upload
custom_parser_import: 'upload_parser.dart'
dart_type:
name: MultipartFile
imports:
- 'package:http/http.dart'
clients:
- graphql
- graphql_flutter
outputDirectory: /lib/graphql_gen/
assetsPath: "**.graphql"
scalars:
Long:
type: int
Upload: # Not used in flutter frontend.
type: String
slang_build_runner:
options:
base_locale: de
Expand Down
2 changes: 1 addition & 1 deletion frontend/graphql_queries/cards/card_activation.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mutation ActivateCard($project: String!, $cardInfoHashBase64: String!, $activationSecretBase64: String!, $overwrite: Boolean!) {
activateCard(project: $project, cardInfoHashBase64: $cardInfoHashBase64, activationSecretBase64: $activationSecretBase64, overwrite: $overwrite) {
activation: activateCard(project: $project, cardInfoHashBase64: $cardInfoHashBase64, activationSecretBase64: $activationSecretBase64, overwrite: $overwrite) {
activationState,
totpSecret,
activationTimeStamp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query CardVerificationByHash($project: String!, $card: CardVerificationModelInput!) {
verifyCardInProjectV2(project: $project, card: $card){
verification: verifyCardInProjectV2(project: $project, card: $card){
valid,
verificationTimeStamp
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/graphql_queries/regions/get_regions.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query getRegions($project: String!) {
regionsInProject(project: $project) {
regions: regionsInProject(project: $project) {
id,
prefix,
name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query getRegionsById($project: String!, $ids: [Int!]!) {
regionsByIdInProject(project: $project, ids: $ids) {
regions: regionsByIdInProject(project: $project, ids: $ids) {
id,
prefix,
name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query AcceptingStoreById($project: String!, $ids: [Int!]!) {
physicalStoresByIdInProject(project: $project, ids: $ids) {
stores: physicalStoresByIdInProject(project: $project, ids: $ids) {
id,
coordinates {
lat,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query AcceptingStoreSummaryById($project: String!, $ids: [Int!]!) {
physicalStoresByIdInProject(project: $project, ids: $ids) {
stores: physicalStoresByIdInProject(project: $project, ids: $ids) {
id,
store {
name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query AcceptingStoresSearch($project: String!, $params: SearchParamsInput!) {
searchAcceptingStoresInProject(project: $project, params: $params) {
stores: searchAcceptingStoresInProject(project: $project, params: $params) {
id
name
description
Expand Down
4 changes: 2 additions & 2 deletions frontend/lib/favorites/favorite_store.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:ehrenamtskarte/graphql/graphql_api.graphql.dart';
import 'package:ehrenamtskarte/graphql_gen/graphql_queries/stores/accepting_store_by_id.graphql.dart';

class FavoriteStore {
final int storeId;
final String storeName;
final int categoryId;

AcceptingStoreById$Query$PhysicalStore? physicalStore;
Query$AcceptingStoreById$stores? physicalStore;

FavoriteStore(this.storeId, this.storeName, this.categoryId);

Expand Down
13 changes: 6 additions & 7 deletions frontend/lib/favorites/favorites_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';

import 'package:ehrenamtskarte/graphql/graphql_api.graphql.dart';
import 'package:ehrenamtskarte/home/home_page.dart';
import 'package:ehrenamtskarte/favorites/favorites_model.dart';
import 'package:ehrenamtskarte/favorites/favorite_store.dart';
Expand All @@ -14,6 +13,7 @@ import 'package:ehrenamtskarte/store_widgets/removed_store_summary.dart';
import 'package:ehrenamtskarte/configuration/configuration.dart';
import 'package:ehrenamtskarte/l10n/translations.g.dart';
import 'package:provider/provider.dart';
import 'package:ehrenamtskarte/graphql_gen/graphql_queries/stores/accepting_store_by_id.graphql.dart';

class FavoritesLoader extends StatefulWidget {
const FavoritesLoader({super.key});
Expand Down Expand Up @@ -93,27 +93,26 @@ class FavoritesLoaderState extends State<FavoritesLoader> {
}
}

Future<AcceptingStoreById$Query$PhysicalStore?> _fetchPhysicalStore(int storeId) async {
Future<Query$AcceptingStoreById$stores?> _fetchPhysicalStore(int storeId) async {
final projectId = Configuration.of(context).projectId;

final query = AcceptingStoreByIdQuery(variables: AcceptingStoreByIdArguments(project: projectId, ids: [storeId]));

final client = _client;
if (client == null) {
throw Exception('GraphQL client is not yet initialized!');
}

final result = await client.query(QueryOptions(document: query.document, variables: query.getVariablesMap()));
final result = await client.query$AcceptingStoreById(Options$Query$AcceptingStoreById(
variables: Variables$Query$AcceptingStoreById(project: projectId, ids: [storeId])));
final exception = result.exception;
if (result.hasException && exception != null) {
throw exception;
}

final data = result.data;
final data = result.parsedData;
if (data == null) {
throw Exception('Fetched data is null');
}
return query.parse(data).physicalStoresByIdInProject.firstOrNull;
return data.stores.firstOrNull;
}

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,36 @@
import 'package:ehrenamtskarte/graphql/graphql_api.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:ehrenamtskarte/graphql_gen/graphql_queries/cards/card_activation.graphql.dart';

Future<ActivateCard$Mutation$CardActivationResultModel> activateCode({
Future<Mutation$ActivateCard$activation> activateCode({
required GraphQLClient client,
required String projectId,
required String cardInfoHashBase64,
required String activationSecretBase64,
required bool overwriteExisting,
}) async {
final activateCard = ActivateCardMutation(
variables: ActivateCardArguments(
project: projectId,
overwrite: overwriteExisting,
activationSecretBase64: activationSecretBase64,
cardInfoHashBase64: cardInfoHashBase64,
),
);
final mutationOptions = MutationOptions(
fetchPolicy: FetchPolicy.noCache,
document: activateCard.document,
variables: activateCard.getVariablesMap(),
);
final mutationOptions = Options$Mutation$ActivateCard(
fetchPolicy: FetchPolicy.noCache,
variables: Variables$Mutation$ActivateCard(
project: projectId,
overwrite: overwriteExisting,
activationSecretBase64: activationSecretBase64,
cardInfoHashBase64: cardInfoHashBase64,
));

try {
final mutationResult = await client.mutate(mutationOptions);
final mutationResult = await client.mutate$ActivateCard(mutationOptions);
final exception = mutationResult.exception;
if (exception != null) {
throw exception;
}

final data = mutationResult.data;
final data = mutationResult.parsedData;

if (data == null) {
throw const ServerCardActivationException('Server returned null.');
}

final parsedResult = activateCard.parse(data);
return parsedResult.activateCard;
return data.activation;
} on Object catch (e) {
throw ServerCardActivationException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:ehrenamtskarte/configuration/configuration.dart';
import 'package:ehrenamtskarte/graphql/graphql_api.graphql.dart';
import 'package:ehrenamtskarte/graphql_gen/graphql_queries/regions/get_regions_by_id.graphql.dart';
import 'package:ehrenamtskarte/identification/id_card/id_card.dart';
import 'package:ehrenamtskarte/proto/card.pb.dart';
import 'package:flutter/cupertino.dart';
Expand All @@ -23,23 +23,18 @@ class IdCardWithRegionQuery extends StatelessWidget {
return IdCard(cardInfo: cardInfo, region: null, isExpired: isExpired, isNotYetValid: isNotYetValid);
}

final regionsQuery = GetRegionsByIdQuery(
variables: GetRegionsByIdArguments(
project: projectId,
ids: [regionId],
),
);
return Query(
options: QueryOptions(
document: regionsQuery.document,
variables: regionsQuery.getVariablesMap(),
fetchPolicy: FetchPolicy.cacheFirst),
return Query$getRegionsById$Widget(
options: Options$Query$getRegionsById(
fetchPolicy: FetchPolicy.cacheFirst,
variables: Variables$Query$getRegionsById(
project: projectId,
ids: [regionId],
),
),
builder: (result, {refetch, fetchMore}) {
final fetchedData = result.data;
final fetchedData = result.parsedData;

final region = result.isLoading || result.hasException || fetchedData == null
? null
: regionsQuery.parse(fetchedData).regionsByIdInProject[0];
final region = result.isLoading || result.hasException || fetchedData == null ? null : fetchedData.regions[0];
return IdCard(
cardInfo: cardInfo,
region: region != null ? Region(region.prefix, region.name) : null,
Expand Down
10 changes: 5 additions & 5 deletions frontend/lib/identification/util/activate_card.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:convert';

import 'package:ehrenamtskarte/configuration/configuration.dart';
import 'package:ehrenamtskarte/graphql/graphql_api.graphql.dart';
import 'package:ehrenamtskarte/graphql_gen/schema.graphql.dart';
import 'package:ehrenamtskarte/identification/activation_workflow/activate_code.dart';
import 'package:ehrenamtskarte/identification/activation_workflow/activation_exception.dart';
import 'package:ehrenamtskarte/identification/activation_workflow/activation_existing_card_dialog.dart';
Expand Down Expand Up @@ -46,7 +46,7 @@ Future<bool> activateCard(
);

switch (activationResult.activationState) {
case ActivationState.success:
case Enum$ActivationState.success:
if (activationResult.totpSecret == null) {
await reportError('TotpSecret is null during activation', null);
throw const ActivationInvalidTotpSecretException();
Expand All @@ -72,17 +72,17 @@ Future<bool> activateCard(
if (Navigator.canPop(context)) Navigator.maybePop(context);
}
return true;
case ActivationState.revoked:
case Enum$ActivationState.revoked:
if (context.mounted) {
await ActivationErrorDialog.showErrorDialog(context, t.identification.codeRevoked);
}
return false;
case ActivationState.failed:
case Enum$ActivationState.failed:
if (context.mounted) {
await ActivationErrorDialog.showErrorDialog(context, t.identification.codeInvalid);
}
return false;
case ActivationState.didNotOverwriteExisting:
case Enum$ActivationState.did_not_overwrite_existing:
if (overwriteExisting) {
throw const ActivationDidNotOverwriteExisting();
}
Expand Down
Loading