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

basic setup #1

Merged
merged 1 commit into from
Aug 31, 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
12 changes: 12 additions & 0 deletions demo/client/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { React } from '../deps.ts';

export class App extends React.Component {

render() {
return (
<div>
<h1>Hello World</h1>
</div>
)
}
}
17 changes: 17 additions & 0 deletions demo/client/assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<!-- <link rel="stylesheet" href="./style.css"> -->
<title>Document</title>
</head>

<body>
<div id='root'>
<h1>Hi there</h1>
</div>
<!-- <script type="module" src="./index.js"></script> -->
</body>

</html>
7 changes: 7 additions & 0 deletions demo/client/assets/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { React, ReactDOM } from '../../deps.ts';
import { App } from '../App.jsx';

ReactDOM.render(
React.createElement(App),
document.getElementById('root')
);
Empty file added demo/client/assets/style.css
Empty file.
14 changes: 14 additions & 0 deletions demo/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Application, Router, send } from "https://deno.land/x/oak/mod.ts";
import { applyGraphQL, gql } from "https://deno.land/x/oak_graphql/mod.ts";
import { default as React } from "https://dev.jspm.io/react@16.13.1";
import { default as ReactDOM } from "https://dev.jspm.io/react-dom@16.13.1";

export {
Application,
Router,
send,
applyGraphQL,
gql,
React,
ReactDOM
};
76 changes: 76 additions & 0 deletions demo/server/server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { Application, Router } from "https://deno.land/x/oak@v6.0.1/mod.ts";
import React from "https://dev.jspm.io/react@16.13.1";
import { default as ReactDomServer } from "https://dev.jspm.io/react-dom@16.13.1/server";
import { App } from '../client/App.jsx';
import { applyGraphQL, gql } from "https://deno.land/x/oak_graphql/mod.ts";

const app = new Application();
const port = 8080;

const router = new Router();

// router.get('/', await (ctx) => {
// Deno.readTextFile
// })

// router.get("/", handlePage);

declare global {
namespace JSX {
interface IntrinsicElements {
[key: string]: any;
}
}
}

function handlePage(ctx: any) {
try {
const body = (ReactDomServer as any).renderToString(<App />);
ctx.response.body = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body >
<div id="root">${body}</div>
</body>
</html>`;
} catch (error) {
console.error(error);
}
}

const GraphQLService = await applyGraphQL({
Router,
typeDefs: (gql as any)`
type Book {
title: String!
author: String!
description: String
coverPrice: Int!
publicationDate: String
publisher: String
id: Int!
}

type Query {
books: [Book]
book (id: Int): Book
}
`, // need
resolvers: {
// Query: {
// book
// }
} // need
})


app.use(GraphQLService.routes(), GraphQLService.allowedMethods());
app.use(router.routes());
app.use(router.allowedMethods());

console.log("server is running on http://localhost:8080/");
await app.listen({ port: port });