Compare commits

..

18 commits

Author SHA1 Message Date
thomashii
e8c109bce6 Updated dependencies 2023-06-23 21:02:40 +08:00
thomashii
c161ad984b Updated to v8 2023-06-19 23:35:09 +08:00
Thomas Hii
71e10b57d2
Merge pull request #4 from dukefirehawk/v6/angel3-graphql
V6/angel3 graphql
2022-04-26 09:16:41 +08:00
thomashii
b3b5d01aec Updated log message 2022-04-26 08:22:40 +08:00
thomashii
563f7f8dde Updated to SDK 2.16.0 2022-04-26 08:11:53 +08:00
thomashii
8facd65c14 Updated packages 2022-03-18 09:20:40 +08:00
thomashii
d8c3736955 Updated graphql template 2021-09-25 18:39:19 +08:00
thomashii
8c63811c50 Updated packages 2021-08-19 08:25:45 +08:00
thomashii
5c4eded653 Updated graphql 2021-07-17 13:05:34 +08:00
thomashii
16565c26cd Updated angel3-graphql 2021-06-14 09:37:53 +08:00
thomashii
9d9a94965e Migrated to NNBD 2021-06-14 09:28:20 +08:00
thomashii
77b61d30ed Graphql template for SDK 2.12.x 2021-03-07 20:59:21 +08:00
Tobe O
35b4706078 Merge branch 'master' into graphql 2019-10-09 14:27:01 -04:00
Tobe O
9f59ab1336 Merge branch 'master' into graphql 2019-10-09 14:22:05 -04:00
Tobe O
45f1a2f6f6 Merge branch 'master' into graphql 2019-05-01 19:33:15 -04:00
Tobe O
708502e0dc Merge branch 'master' into graphql 2019-05-01 19:30:25 -04:00
Tobe O
0148812c60 Add Graphiql redirect, css, etc. 2019-04-29 13:20:47 -04:00
Tobe O
9cfb56f123 Complete todo api 2019-04-29 13:12:23 -04:00
20 changed files with 333 additions and 97 deletions

3
.github/FUNDING.yml vendored
View file

@ -1,3 +0,0 @@
# These are supported funding model platforms
github: [thosakwe]

28
.gitignore vendored
View file

@ -11,7 +11,6 @@
.project .project
.pub/ .pub/
.scripts-bin/ .scripts-bin/
.metals/
build/ build/
**/packages/ **/packages/
@ -38,27 +37,7 @@ pubspec.lock
# User-specific stuff: # User-specific stuff:
.idea/workspace.xml .idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
.vscode/
## File-based project format: ## File-based project format:
*.iws *.iws
@ -81,11 +60,8 @@ crashlytics-build.properties
fabric.properties fabric.properties
### VSCode template ### VSCode template
.vscode/* .vscode/
!.vscode/settings.json .metals/
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
logs/ logs/
*.pem *.pem

View file

@ -1,12 +0,0 @@
Primary Authors
===============
* __[Thomas Hii](dukefirehawk.apps@gmail.com)__
Thomas is the current maintainer of the code base. He has refactored and migrated the
code base to support NNBD.
* __[Tobe O](thosakwe@gmail.com)__
Tobe has written much of the original code prior to NNBD migration. He has moved on and
is no longer involved with the project.

View file

@ -1,25 +0,0 @@
# Contribution
Any help from the open-source community is always welcome and needed:
1. Found an issue?
- Please [fill a bug report][tracker] with error message and steps to reproduce it.
2. Wish a feature?
- Open a feature request with use cases.
3. Are you using and liking the project?
- Create an article about your use case
- Do a post on your likes and dislikes
- Make a donation.
4. Are you a developer?
- Fix a bug and send a [pull request][pull_request]
- Implement a new feature
- Improve the Unit Tests
- Improve the [User Guide][doc] and send a [document pull request][doc_repo]
5. Have you already helped in any way?
- **Many thanks to the contributors and everybody that uses this project!**
[tracker]: https://github.com/dukefirehawk/angel/issues
[pull_request]: https://github.com/dukefirehawk/angel/pulls
[doc]: https://angel3-docs.dukefirehawk.com
[doc_repo]: https://github.com/dukefirehawk/angel3-guide/pulls

View file

@ -1,7 +1,6 @@
# Graphql Starter Application for Angel3 framework
# Basic Starter Application for Angel3 framework This is a graphql starter application for [Angel3 framework](https://angel3-framework.web.app) which is a full-stack Web framework in Dart.
This is a basic starter application for [Angel3 framework](https://angel3-framework.web.app) which is a full-stack Web framework in Dart.
## Installation & Setup ## Installation & Setup
@ -32,3 +31,5 @@ This is a basic starter application for [Angel3 framework](https://angel3-framew
Visit the [Developer Guide](https://angel3-docs.dukefirehawk.com/guides) for dozens of guides and resources, including video tutorials, to get up and running as quickly as possible with Angel3. Visit the [Developer Guide](https://angel3-docs.dukefirehawk.com/guides) for dozens of guides and resources, including video tutorials, to get up and running as quickly as possible with Angel3.
Examples and complete projects can be found [here](https://angel3-framework.web.app/#/examples). Examples and complete projects can be found [here](https://angel3-framework.web.app/#/examples).
You can also view the [API Documentation](https://pub.dev/documentation/angel3_framework/latest/).

View file

@ -1,10 +1,10 @@
import 'dart:io'; import 'dart:io';
import 'package:logging/logging.dart';
import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart'; import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart';
import 'package:angel/angel.dart';
import 'package:angel3_container/mirrors.dart'; import 'package:angel3_container/mirrors.dart';
import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_hot/angel3_hot.dart'; import 'package:angel3_hot/angel3_hot.dart';
import 'package:angel/angel.dart'; import 'package:logging/logging.dart';
void main() async { void main() async {
// Watch the config/ and web/ directories for changes, and hot-reload the server. // Watch the config/ and web/ directories for changes, and hot-reload the server.

View file

@ -1,6 +1,6 @@
import 'package:angel/angel.dart';
import 'package:angel3_container/mirrors.dart'; import 'package:angel3_container/mirrors.dart';
import 'package:angel3_production/angel3_production.dart'; import 'package:angel3_production/angel3_production.dart';
import 'package:angel/angel.dart';
// NOTE: By default, the Runner class does not use the `MirrorsReflector`, or any // NOTE: By default, the Runner class does not use the `MirrorsReflector`, or any
// reflector, by default. // reflector, by default.

View file

@ -1,4 +1,3 @@
/// Configuration for this Angel instance.
import 'package:angel3_configuration/angel3_configuration.dart'; import 'package:angel3_configuration/angel3_configuration.dart';
import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_jael/angel3_jael.dart'; import 'package:angel3_jael/angel3_jael.dart';

View file

@ -1,4 +1,3 @@
/// Custom plugins go here.
import 'dart:async'; import 'dart:async';
import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';

11
lib/src/models/todo.dart Normal file
View file

@ -0,0 +1,11 @@
import 'package:angel3_serialize/angel3_serialize.dart';
import 'package:graphql_schema2/graphql_schema2.dart';
part 'todo.g.dart';
@graphQLClass
@serializable
abstract class _Todo extends Model {
String? get text;
bool? get isComplete;
}

155
lib/src/models/todo.g.dart Normal file
View file

@ -0,0 +1,155 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'todo.dart';
// **************************************************************************
// JsonModelGenerator
// **************************************************************************
@generatedSerializable
class Todo extends _Todo {
Todo({this.id, this.text, this.isComplete, this.createdAt, this.updatedAt});
@override
final String? id;
@override
final String? text;
@override
final bool? isComplete;
@override
final DateTime? createdAt;
@override
final DateTime? updatedAt;
Todo copyWith(
{String? id,
String? text,
bool? isComplete,
DateTime? createdAt,
DateTime? updatedAt}) {
return Todo(
id: id ?? this.id,
text: text ?? this.text,
isComplete: isComplete ?? this.isComplete,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt);
}
@override
bool operator ==(other) {
return other is _Todo &&
other.id == id &&
other.text == text &&
other.isComplete == isComplete &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
}
@override
int get hashCode {
return hashObjects([id, text, isComplete, createdAt, updatedAt]);
}
@override
String toString() {
return 'Todo(id=$id, text=$text, isComplete=$isComplete, createdAt=$createdAt, updatedAt=$updatedAt)';
}
Map<String, dynamic> toJson() {
return TodoSerializer.toMap(this);
}
}
// **************************************************************************
// SerializerGenerator
// **************************************************************************
const TodoSerializer todoSerializer = TodoSerializer();
class TodoEncoder extends Converter<Todo, Map> {
const TodoEncoder();
@override
Map convert(Todo model) => TodoSerializer.toMap(model);
}
class TodoDecoder extends Converter<Map, Todo> {
const TodoDecoder();
@override
Todo convert(Map map) => TodoSerializer.fromMap(map);
}
class TodoSerializer extends Codec<Todo, Map> {
const TodoSerializer();
@override
TodoEncoder get encoder => const TodoEncoder();
@override
TodoDecoder get decoder => const TodoDecoder();
static Todo fromMap(Map map) {
return Todo(
id: map['id'] as String?,
text: map['text'] as String?,
isComplete: map['is_complete'] as bool?,
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime?)
: DateTime.parse(map['created_at'].toString()))
: null,
updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime?)
: DateTime.parse(map['updated_at'].toString()))
: null);
}
static Map<String, dynamic> toMap(_Todo model) {
return {
'id': model.id,
'text': model.text,
'is_complete': model.isComplete,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String()
};
}
}
abstract class TodoFields {
static const List<String> allFields = <String>[
id,
text,
isComplete,
createdAt,
updatedAt
];
static const String id = 'id';
static const String text = 'text';
static const String isComplete = 'is_complete';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
}
// **************************************************************************
// _GraphQLGenerator
// **************************************************************************
/// Auto-generated from [Todo].
final GraphQLObjectType todoGraphQLType =
objectType('Todo', isInterface: false, interfaces: [], fields: [
field('id', graphQLString),
field('text', graphQLString),
field('is_complete', graphQLBoolean),
field('created_at', graphQLDate),
field('updated_at', graphQLDate),
field('idAsInt', graphQLInt)
]);

View file

@ -0,0 +1,20 @@
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_graphql/angel3_graphql.dart';
import 'package:graphql_server2/graphql_server2.dart';
import 'schema.dart';
/// Configures the [app] to server GraphQL.
void configureServer(Angel app) {
// Create a [GraphQL] service instance, using our schema.
var schema = createSchema(app);
var graphQL = GraphQL(schema);
// Mount a handler that responds to GraphQL queries.
app.all('/graphql', graphQLHttp(graphQL));
// In development, serve the GraphiQL IDE/editor.
// More info: https://github.com/graphql/graphiql
if (!app.environment.isProduction) {
app.get('/graphiql', graphiQL());
}
}

View file

@ -0,0 +1,22 @@
import 'package:angel3_framework/angel3_framework.dart';
import 'package:graphql_schema2/graphql_schema2.dart';
import 'todo.dart';
/// Creates a GraphQL schema that manages an in-memory store of
/// Todo items.
GraphQLSchema createSchema(Angel app) {
var queryType = objectType(
'TodoQuery',
fields: todoQueryFields(app),
);
var mutationType = objectType(
'TodoMutation',
fields: todoMutationFields(app),
);
return graphQLSchema(
queryType: queryType,
mutationType: mutationType,
);
}

View file

@ -0,0 +1,73 @@
import 'package:angel/src/models/todo.dart';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_graphql/angel3_graphql.dart';
import 'package:graphql_schema2/graphql_schema2.dart';
/// Find or create an in-memory Todo store.
MapService? _getTodoService(Angel app) {
const key = 'todoService';
// If there is already an existing singleton, return it.
if (app.container.hasNamed(key)) {
return app.container.findByName<MapService>(key);
}
// Create an in-memory service. We will use this
// as the backend to store Todo objects, serialized to Maps.
var mapService = MapService();
// Register this service as a named singleton in the app container,
// so that we do not inadvertently create another instance.
app.container.registerNamedSingleton(key, mapService);
return mapService;
}
/// Returns fields to be inserted into the query type.
Iterable<GraphQLObjectField> todoQueryFields(Angel app) {
var todoService = _getTodoService(app)!;
// Here, we use special resolvers to read data from our store.
return [
field(
'todos',
listOf(todoGraphQLType),
resolve: resolveViaServiceIndex(todoService),
),
field(
'todo',
todoGraphQLType,
resolve: resolveViaServiceRead(todoService),
inputs: [
GraphQLFieldInput('id', graphQLString.nonNullable()),
],
),
];
}
/// Returns fields to be inserted into the query type.
Iterable<GraphQLObjectField> todoMutationFields(Angel app) {
var todoService = _getTodoService(app)!;
var todoInputType = todoGraphQLType.toInputObject('TodoInput');
// This time, we use resolvers to modify the data in the store.
return [
field(
'createTodo',
todoGraphQLType,
resolve: resolveViaServiceCreate(todoService),
inputs: [
GraphQLFieldInput('data', todoInputType.nonNullable()),
],
),
field(
'modifyTodo',
todoGraphQLType,
resolve: resolveViaServiceModify(todoService),
inputs: [
GraphQLFieldInput('id', graphQLString.nonNullable()),
GraphQLFieldInput('data', todoInputType.nonNullable()),
],
),
];
}

View file

@ -1,8 +1,8 @@
/// This app's route configuration.
import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_static/angel3_static.dart'; import 'package:angel3_static/angel3_static.dart';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'controllers/controllers.dart' as controllers; import 'controllers/controllers.dart' as controllers;
import 'graphql/graphql.dart' as graphql;
/// Put your app routes here! /// Put your app routes here!
/// ///
@ -14,6 +14,9 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
// Typically, you want to mount controllers first, after any global middleware. // Typically, you want to mount controllers first, after any global middleware.
await app.configure(controllers.configureServer); await app.configure(controllers.configureServer);
// Mount our GraphQL routes as well.
await app.configure(graphql.configureServer);
// Render `views/hello.jl` when a user visits the application root. // Render `views/hello.jl` when a user visits the application root.
app.get('/', (req, res) => res.render('hello')); app.get('/', (req, res) => res.render('hello'));

View file

@ -1,4 +1,3 @@
/// Declare services here!
import 'dart:async'; import 'dart:async';
import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';

View file

@ -1,25 +1,30 @@
name: angel name: angel
version: 1.0.0 description: A graphql starter application for Angel3 framework
description: A basic starter application template for Angel3 framework
publish_to: none publish_to: none
environment: environment:
sdk: '>=2.16.0 <3.0.0' sdk: '>=3.0.0 <4.0.0'
dependencies: dependencies:
angel3_auth: ^6.0.0 angel3_auth: ^8.0.0
angel3_configuration: ^6.0.0 angel3_configuration: ^8.0.0
angel3_framework: ^6.0.0 angel3_framework: ^8.0.0
angel3_jael: ^6.0.0 angel3_graphql: ^8.0.0
angel3_production: ^6.0.0 angel3_jael: ^8.0.0
angel3_static: ^6.0.0 angel3_production: ^8.0.0
angel3_validate: ^6.0.0 angel3_container: ^8.0.0
belatuk_pretty_logging: ^4.0.0 angel3_static: ^8.0.0
angel3_validate: ^8.0.0
angel3_serialize: ^8.0.0
graphql_server2: ^6.0.0
graphql_schema2: ^6.0.0
file: ^7.0.0
logging: ^1.2.0
dev_dependencies: dev_dependencies:
angel3_hot: ^6.0.0 angel3_hot: ^8.0.0
angel3_test: ^6.0.0 angel3_serialize_generator: ^8.0.0
angel3_test: ^8.0.0
graphql_generator2: ^6.0.0
belatuk_pretty_logging: ^6.0.0
build_runner: ^2.0.4
io: ^1.0.0 io: ^1.0.0
test: ^1.21.0 test: ^1.21.0
lints: ^1.0.0 lints: ^2.1.1

View file

@ -1,7 +1,7 @@
import 'package:angel/angel.dart';
import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_test/angel3_test.dart'; import 'package:angel3_test/angel3_test.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'package:angel/angel.dart';
// Angel also includes facilities to make testing easier. // Angel also includes facilities to make testing easier.
// //

View file

@ -1,5 +1,8 @@
<extend src="layout.jael"> <extend src="layout.jael">
<block name="content"> <block name="content">
<div class="title">Angel</div> <div class="title">Angel</div>
<p>
<a href="/graphiql">Click here</a> to access GraphiQL.
</p>
</block> </block>
</extend> </extend>

View file

@ -11,6 +11,16 @@ body {
font-family: 'Lato', sans-serif; font-family: 'Lato', sans-serif;
} }
a {
color: rgb(8, 114, 175) !important;
font-weight: 900;
text-decoration: none;
}
p {
font-size: 1.3em;
}
.container { .container {
text-align: center; text-align: center;
display: table-cell; display: table-cell;