Skip to content

Commit

Permalink
✅ IMPROVE: tests (HoudiniGraphql#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycouet committed Jun 13, 2022
1 parent 83cfb97 commit b2e22ea
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 54 deletions.
61 changes: 8 additions & 53 deletions integration/api/graphql.mjs
Original file line number Diff line number Diff line change
@@ -1,62 +1,14 @@
import gql from 'graphql-tag';
import { GraphQLScalarType, Kind } from 'graphql';
import { createPubSub, GraphQLYogaError } from '@graphql-yoga/node';
import { sleep } from '@kitql/helper';
import { GraphQLScalarType, Kind } from 'graphql';
import { connectionFromArray } from 'graphql-relay';

const pubSub = createPubSub();

export const typeDefs = gql`
scalar DateTime
type Query {
usersList(snapshot: String!, limit: Int = 4, offset: Int): [User!]!
user(snapshot: String!, id: ID!, tmp: Boolean): User!
avgYearsBirthDate: Float!
usersConnection(
snapshot: String!
first: Int
after: String
last: Int
before: String
): UserConnection!
node(id: ID!): Node
}
type Mutation {
addUser(snapshot: String!, name: String!, birthDate: DateTime!, delay: Int): User!
updateUser(id: ID!, name: String, snapshot: String!, birthDate: DateTime): User!
}
type User implements Node {
id: ID!
name: String!
birthDate: DateTime!
friendsList(limit: Int, offset: Int): [User!]!
friendsConnection(first: Int, after: String, last: Int, before: String): UserConnection!
}
type UserConnection {
edges: [UserEdge!]!
pageInfo: PageInfo!
}
type UserEdge {
node: User
cursor: String
}
import fs from 'fs-extra';

type PageInfo {
endCursor: String
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
}
const pubSub = createPubSub();

interface Node {
id: ID!
}
`;
const sourceFiles = ['api/schema.graphql', 'api/schema-hello.graphql'];
export const typeDefs = sourceFiles.map((filepath) => fs.readFileSync(filepath, 'utf-8'));

// example data
const data = [
Expand Down Expand Up @@ -85,6 +37,9 @@ function getSnapshot(snapshot) {

export const resolvers = {
Query: {
hello: () => {
return 'Hello World! // From Houdini!';
},
usersList: (_, args) => {
return [...getSnapshot(args.snapshot)].splice(args.offset || 0, args.limit);
},
Expand Down
3 changes: 3 additions & 0 deletions integration/api/schema-hello.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extend type Query {
hello: String!
}
3 changes: 3 additions & 0 deletions integration/src/lib/graphql/operations/QUERY.Hello.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
query Hello {
hello
}
7 changes: 7 additions & 0 deletions integration/src/routes/stores/ssr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ test.describe('SSR Page', () => {
await expectNoGraphQLRequest(page);
});

test('expect the hello result (from another *.graphql file)', async ({ page }) => {
await page.goto(routes.Stores_SSR);

const content = await page.locator('div[id=result]').textContent();
expect(content).toBe('Hello World! // From Houdini!');
});

test('Right Data in <li> elements (SSR)', async ({ page }) => {
await page.goto(routes.Stores_SSR);

Expand Down
7 changes: 6 additions & 1 deletion integration/src/routes/stores/ssr.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script context="module" lang="ts">
import { GQL_usersList } from '$houdini';
import { GQL_Hello, GQL_usersList } from '$houdini';
import type { LoadEvent } from '@sveltejs/kit';
export async function load(event: LoadEvent) {
await GQL_usersList.fetch({ event });
await GQL_Hello.fetch({ event });
return {};
}
</script>
Expand All @@ -17,3 +18,7 @@
</li>
{/each}
</ul>

<div id="result">
{$GQL_Hello.data?.hello}
</div>

0 comments on commit b2e22ea

Please sign in to comment.