mirror of
https://github.com/cupcakearmy/blog-typescript-graphql.git
synced 2025-12-09 22:04:59 +00:00
initial push
This commit is contained in:
21
src/app.html
Normal file
21
src/app.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="description" content="" />
|
||||
<link rel="icon" href="/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="stylesheet" href="https://unpkg.com/tachyons@4.12.0/css/tachyons.min.css" />
|
||||
%svelte.head%
|
||||
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans',
|
||||
'Helvetica Neue', sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="svelte">%svelte.body%</div>
|
||||
</body>
|
||||
</html>
|
||||
1
src/global.d.ts
vendored
Normal file
1
src/global.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="@sveltejs/kit" />
|
||||
1377
src/lib/gql/gen.ts
Normal file
1377
src/lib/gql/gen.ts
Normal file
File diff suppressed because it is too large
Load Diff
5
src/lib/gql/index.ts
Normal file
5
src/lib/gql/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { GraphQLClient } from 'graphql-request'
|
||||
import { getSdk } from './gen'
|
||||
|
||||
const client = new GraphQLClient('https://api.spacex.land/graphql/')
|
||||
export const SDK = getSdk(client)
|
||||
22
src/lib/gql/root.graphql
Normal file
22
src/lib/gql/root.graphql
Normal file
@@ -0,0 +1,22 @@
|
||||
query LaunchpadsMany {
|
||||
launchpads(limit: 10) {
|
||||
id
|
||||
name
|
||||
location {
|
||||
name
|
||||
}
|
||||
successful_launches
|
||||
status
|
||||
}
|
||||
}
|
||||
|
||||
query LaunchByYear($year: String!) {
|
||||
launches(find: { launch_year: $year }) {
|
||||
mission_id
|
||||
mission_name
|
||||
launch_date_utc
|
||||
rocket {
|
||||
rocket_name
|
||||
}
|
||||
}
|
||||
}
|
||||
58
src/routes/index.svelte
Normal file
58
src/routes/index.svelte
Normal file
@@ -0,0 +1,58 @@
|
||||
<script lang="ts" context="module">
|
||||
import { SDK } from '$lib/gql'
|
||||
import type { Load } from '@sveltejs/kit'
|
||||
|
||||
export const load: Load = async () => ({
|
||||
props: {
|
||||
launchpads: await SDK.LaunchpadsMany(),
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { GQLLaunchpadsManyQuery } from '$lib/gql/gen'
|
||||
|
||||
export let launchpads: GQLLaunchpadsManyQuery
|
||||
|
||||
let needle: string = '2020'
|
||||
$: launches = SDK.LaunchByYear({ year: needle })
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<h1>SpaceX Land</h1>
|
||||
|
||||
<h2>Launchpads</h2>
|
||||
{#each launchpads.launchpads as launchpad (launchpad.id)}
|
||||
<div class="mb3">
|
||||
<b>{launchpad.name}</b>
|
||||
<br />
|
||||
{launchpad.location.name}
|
||||
<br /> <i>Launches:</i>
|
||||
{launchpad.successful_launches}
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
<h2>Launches</h2>
|
||||
<input bind:value={needle} />
|
||||
{#await launches}
|
||||
<br />
|
||||
Loading...
|
||||
{:then launches}
|
||||
{#each launches.launches as launch}
|
||||
<div class="mb3">
|
||||
<b>{launch.mission_name}</b>
|
||||
<br />
|
||||
<i>Rocket:</i>
|
||||
{launch.rocket.rocket_name}
|
||||
</div>
|
||||
{/each}
|
||||
{/await}
|
||||
</main>
|
||||
|
||||
<style>
|
||||
main {
|
||||
padding: 1em;
|
||||
max-width: 50rem;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user