Skip to content

Commit

Permalink
All postgres tables generated correctly (AFAICT)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie committed Jan 6, 2020
1 parent cf1999f commit ddab345
Show file tree
Hide file tree
Showing 22 changed files with 788 additions and 334 deletions.
5 changes: 1 addition & 4 deletions api-tests/DateTime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
const postedAt = '2018-08-31T06:49:07.000Z';

const createPost = await create('Post', { postedAt });

// Create an item that does the linking
const { data } = await graphqlRequest({
const { data, errors } = await graphqlRequest({
keystone,
query: `
query {
Expand All @@ -91,7 +90,6 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
}
`,
});

expect(data).toHaveProperty('Post.postedAt', postedAt);
})
);
Expand All @@ -112,7 +110,6 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
}
`,
});

expect(errors).toBe(undefined);
expect(data).toHaveProperty('createPost.postedAt', postedAt);
})
Expand Down
6 changes: 3 additions & 3 deletions api-tests/queries/relationships.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
);
});

describe('to-many', () => {
describe.only('to-many', () => {
const setup = async create => {
const posts = await Promise.all([
create('Post', { title: 'Hello' }),
Expand All @@ -135,11 +135,11 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
return { posts, users };
};

test(
test.only(
'_every condition',
runner(setupKeystone, async ({ keystone, create }) => {
const { users } = await setup(create);

console.log('----');
// EVERY
const { data, errors } = await graphqlRequest({
keystone,
Expand Down
4 changes: 2 additions & 2 deletions api-tests/relationships/crud/one-to-many.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
})
);

test.failing(
test(
'With nested connect',
runner(setupKeystone, async ({ keystone }) => {
const { companies } = await createInitialData(keystone);
Expand Down Expand Up @@ -221,7 +221,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
})
);

test.failing(
test(
'With nested create',
runner(setupKeystone, async ({ keystone }) => {
const locationName = sampleOne(alphanumGenerator);
Expand Down
10 changes: 5 additions & 5 deletions api-tests/relationships/crud/one-to-one.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
})
);

test.failing(
test(
'With nested connect',
runner(setupKeystone, async ({ keystone }) => {
const { companies } = await createInitialData(keystone);
Expand All @@ -179,7 +179,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
mutation {
createCompany(data: {
location: { create: { name: "${locationName}" company: { connect: { id: "${company.id}" } } } }
}) { id location { id company { id }} }
}) { id location { id company { id } } }
}
`,
});
Expand All @@ -198,7 +198,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
data: { allCompanies },
} = await graphqlRequest({
keystone,
query: `{ allCompanies { id location { id company { id }} } }`,
query: `{ allCompanies { id location { id company { id } } } }`,
});

// The nested company should not have a location
Expand All @@ -213,7 +213,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
})
);

test.failing(
test(
'With nested create',
runner(setupKeystone, async ({ keystone }) => {
const locationName = sampleOne(alphanumGenerator);
Expand Down Expand Up @@ -245,7 +245,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
data: { allCompanies },
} = await graphqlRequest({
keystone,
query: `{ allCompanies { id location { id company { id }} } }`,
query: `{ allCompanies { id location { id company { id } } } }`,
});
expect(
allCompanies.filter(({ id }) => id === Company.id)[0].location.company.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function setupKeystone(adapterName) {
multiAdapterRunners().map(({ runner, adapterName }) =>
describe(`Adapter: ${adapterName}`, () => {
describe('Reconnect', () => {
test.failing(
test(
'Reconnect from the many side',
runner(setupKeystone, async ({ keystone, create }) => {
// Create some notes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
expect(toStr(canaryStudent.teachers)).toHaveLength(0);
expect(toStr(teacher1.students)).toHaveLength(0);
expect(toStr(teacher2.students)).toHaveLength(0);

// Run the query to disconnect the teacher from student
const { data, errors } = await graphqlRequest({
keystone,
Expand All @@ -105,9 +104,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
}
`,
});

expect(errors).toBe(undefined);

let newStudent = data.createStudent;

// Check the link has been broken
Expand Down Expand Up @@ -146,7 +143,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
expect(toStr(teacher2.students)).toHaveLength(0);

// Run the query to disconnect the teacher from student
const { errors } = await graphqlRequest({
const { data, errors } = await graphqlRequest({
keystone,
query: `
mutation {
Expand Down Expand Up @@ -289,7 +286,6 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
compareIds(student2.teachers, [teacher1, teacher2]);
compareIds(teacher1.students, [student1, student2]);
compareIds(teacher2.students, [student1, student2]);

// Run the query to disconnect the teacher from student
const { errors } = await graphqlRequest({
keystone,
Expand All @@ -309,7 +305,6 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
}
`,
});

expect(errors).toBe(undefined);

// Check the link has been broken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
const companyId = data.createCompany.id;
const locationId = data.createCompany.location.id;

const location = await findById('Location', locationId);
const company = await findById('Company', companyId);

// Everything should now be connected
// Everything should now be connected. 1:1 has a single connection on the first list defined.
expect(company.location.toString()).toBe(locationId.toString());
expect(location.company.toString()).toBe(companyId.toString());
})
);
});
Expand Down
31 changes: 27 additions & 4 deletions demo-projects/todo/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
const { Keystone } = require('@keystonejs/keystone');
const { KnexAdapter } = require('@keystonejs/adapter-knex');
const { MongooseAdapter } = require('@keystonejs/adapter-mongoose');
const { Text } = require('@keystonejs/fields');
const { Relationship, Text } = require('@keystonejs/fields');
const { GraphQLApp } = require('@keystonejs/app-graphql');
const { AdminUIApp } = require('@keystonejs/app-admin-ui');
const { StaticApp } = require('@keystonejs/app-static');

const keystone = new Keystone({
name: 'Keystone To-Do List',
// adapter: new KnexAdapter({
// knexOptions: { connection: 'postgres://keystone5:k3yst0n3@localhost:5432/keystone' },
// }),
adapter: new MongooseAdapter(),
});

keystone.createList('Todo', {
schemaDoc: 'A list of things which need to be done',
keystone.createList('Foo', {
fields: {
name: { type: Text, schemaDoc: 'This is the thing you need to do', isRequired: true },
name: { type: Text },
// No reference
a: { type: Relationship, ref: 'Bar' }, // 1:N
b: { type: Relationship, ref: 'Bar', many: true }, // N:N

// With reference
c: { type: Relationship, ref: 'Bar.w' }, // 1:1
d: { type: Relationship, ref: 'Bar.x', many: true }, // 1:N
e: { type: Relationship, ref: 'Bar.y' }, // N:1
f: { type: Relationship, ref: 'Bar.z', many: true }, // N:N
},
});

keystone.createList('Bar', {
fields: {
name: { type: Text },
// With reference
w: { type: Relationship, ref: 'Foo.c' }, // 1:1
x: { type: Relationship, ref: 'Foo.d' }, // 1:N
y: { type: Relationship, ref: 'Foo.e', many: true }, // N:1
z: { type: Relationship, ref: 'Foo.f', many: true }, // N:N
},
});

Expand Down
1 change: 1 addition & 0 deletions demo-projects/todo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"start": "cross-env NODE_ENV=production keystone start"
},
"dependencies": {
"@keystonejs/adapter-knex": "^6.0.0",
"@keystonejs/adapter-mongoose": "^5.1.3",
"@keystonejs/app-admin-ui": "^5.3.0",
"@keystonejs/app-graphql": "^5.0.1",
Expand Down
Loading

0 comments on commit ddab345

Please sign in to comment.