Skip to content

Commit

Permalink
Initial Commit - NextJS, Typescript, GraphQL, TailwindCSS
Browse files Browse the repository at this point in the history
  • Loading branch information
frankievx committed Nov 20, 2020
1 parent ef7ee70 commit c9fc2f4
Show file tree
Hide file tree
Showing 12 changed files with 1,737 additions and 87 deletions.
2 changes: 2 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@
"start": "next start"
},
"dependencies": {
"apollo-server-micro": "^2.19.0",
"graphql": "^15.4.0",
"next": "10.0.2",
"react": "17.0.1",
"react-dom": "17.0.1"
"react-dom": "17.0.1",
"swr": "^0.3.9"
},
"devDependencies": {
"@types/node": "^14.14.9",
"@types/react": "^16.9.56",
"postcss": "^8.1.8",
"postcss-preset-env": "^6.7.0",
"tailwindcss": "^2.0.1",
"typescript": "^4.1.2"
}
}
2 changes: 2 additions & 0 deletions pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import "../styles/tailwind.css";
import '../styles/globals.css'


function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
Expand Down
28 changes: 28 additions & 0 deletions pages/api/graphql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ApolloServer, gql } from 'apollo-server-micro'

const typeDefs = gql`
type Query {
users: [User!]!
}
type User {
name: String
}
`

const resolvers = {
Query: {
users(parent, args, context) {
return [{ name: 'Nextjs' }]
},
},
}

const apolloServer = new ApolloServer({ typeDefs, resolvers })

export const config = {
api: {
bodyParser: false,
},
}

export default apolloServer.createHandler({ path: '/api/graphql' })
3 changes: 2 additions & 1 deletion pages/api/hello.js → pages/api/hello.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next";

export default (req, res) => {
export default (req: NextApiRequest, res: NextApiResponse) => {
res.statusCode = 200
res.json({ name: 'John Doe' })
}
65 changes: 0 additions & 65 deletions pages/index.js

This file was deleted.

29 changes: 29 additions & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import useSWR from 'swr'

const fetcher = (query) =>
fetch('/api/graphql', {
method: 'POST',
headers: {
'Content-type': 'application/json',
},
body: JSON.stringify({ query }),
})
.then((res) => res.json())
.then((json) => json.data)

export default function Index() {
const { data, error } = useSWR('{ users { name } }', fetcher)

if (error) return <div>Failed to load</div>
if (!data) return <div>Loading...</div>

const { users } = data

return (
<div>
{users.map((user, i) => (
<div key={i}>{user.name}</div>
))}
</div>
)
}
3 changes: 3 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
plugins: ["tailwindcss", "postcss-preset-env"],
};
3 changes: 3 additions & 0 deletions styles/tailwind.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
39 changes: 39 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
purge: [],
darkMode: false, // or 'media' or 'class'
theme: {
colors: {
primary: "#6B9080",
primary1: "#6B9080",
secondary: "#D68C45",
secondary2: "#D68C45",
accent: "#FEFEE3",
light: "#F6FFF8",
dark: "#122B1D",
white1: "#fff",
gray: {
100: "#f5f5f5",
200: "#eeeeee",
300: "#e0e0e0",
400: "#bdbdbd",
500: "#9e9e9e",
600: "#757575",
700: "#616161",
800: "#424242",
900: "#212121",
},
},
extend: {},
},
variants: {
cursor: ["responsive", "hover", "focus"],
borderColor: ["responsive", "hover", "focus", "focus-within"],
borderWidth: ["responsive", "hover", "focus", "focus-within"],
backgroundColor: ["hover", "focus", "active", "focus-within"],
textColor: ["responsive", "hover", "focus", "active", "group-focus"],
fontSize: ["responsive", "hover", "focus", "active", "group-focus"],
borderStyle: ["responsive", "hover", "focus", "active", "group-focus"],
extend: {},
},
plugins: [],
};
29 changes: 29 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx", "pages/index.js", "pages/_app.js"
],
"exclude": [
"node_modules"
]
}
Loading

0 comments on commit c9fc2f4

Please sign in to comment.