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 07c184c commit 02f0805
Show file tree
Hide file tree
Showing 22 changed files with 875 additions and 336 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
32 changes: 30 additions & 2 deletions api-tests/relationships/crud/one-to-many.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
})
);

test.failing(
test(
'With nested connect',
runner(setupKeystone, async ({ keystone }) => {
const { companies } = await createInitialData(keystone);
Expand Down Expand Up @@ -211,6 +211,34 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
query: `{ allCompanies { id locations { id company { id } } } }`,
});

// The nested company should not have a location
expect(
allCompanies.filter(({ id }) => id === Company.id)[0].locations[0].company.id
).toEqual(Company.id);
allCompanies
.filter(({ id }) => id !== Company.id)
.forEach(company => {
expect(company.locations).toEqual([]);
});
expect(errors).toBe(undefined);

const { Company, Location } = await getCompanyAndLocation(
keystone,
data.createCompany.id,
data.createCompany.locations[0].id
);

// Everything should now be connected
expect(Company.locations.map(({ id }) => id.toString())).toEqual([Location.id]);
expect(Location.company.id.toString()).toBe(Company.id.toString());

const {
data: { allCompanies },
} = await graphqlRequest({
keystone,
query: `{ allCompanies { id locations { id company { id } } } }`,
});

// The nested company should not have a location
expect(
allCompanies.filter(({ id }) => id === Company.id)[0].locations[0].company.id
Expand All @@ -223,7 +251,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
})
);

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

test.failing(
test(
'With nested connect',
runner(setupKeystone, async ({ keystone }) => {
const { companies } = await createInitialData(keystone);
Expand All @@ -181,7 +181,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 @@ -203,6 +203,33 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
query: `{ allCompanies { id location { id company { id }} } }`,
});

// The nested company should not have a location
expect(
allCompanies.filter(({ id }) => id === Company.id)[0].location.company.id
).toEqual(Company.id);
allCompanies
.filter(({ id }) => id !== Company.id)
.forEach(company => {
expect(company.location).toBe(null);
});
expect(errors).toBe(undefined);

const { Company, Location } = await getCompanyAndLocation(
keystone,
data.createCompany.id,
data.createCompany.location.id
);
// Everything should now be connected
expect(Company.location.id.toString()).toBe(Location.id.toString());
expect(Location.company.id.toString()).toBe(Company.id.toString());

const {
data: { allCompanies },
} = await graphqlRequest({
keystone,
query: `{ allCompanies { id location { id company { id } } } }`,
});

// The nested company should not have a location
expect(
allCompanies.filter(({ id }) => id === Company.id)[0].location.company.id
Expand All @@ -215,7 +242,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
})
);

test.failing(
test(
'With nested create',
runner(setupKeystone, async ({ keystone }) => {
const locationName = sampleOne(alphanumGenerator);
Expand Down Expand Up @@ -257,6 +284,32 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
.forEach(company => {
expect(company.location).toBe(null);
});
expect(errors).toBe(undefined);

const { Company, Location } = await getCompanyAndLocation(
keystone,
data.createCompany.id,
data.createCompany.location.id
);
// Everything should now be connected
expect(Company.location.id.toString()).toBe(Location.id.toString());
expect(Location.company.id.toString()).toBe(Company.id.toString());

// The nested company should not have a location
const {
data: { allCompanies },
} = await graphqlRequest({
keystone,
query: `{ allCompanies { id location { id company { id } } } }`,
});
expect(
allCompanies.filter(({ id }) => id === Company.id)[0].location.company.id
).toEqual(Company.id);
allCompanies
.filter(({ id }) => id !== Company.id)
.forEach(company => {
expect(company.location).toBe(null);
});
})
);
});
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 @@ -90,7 +90,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 @@ -109,9 +108,7 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
}
`,
});

expect(errors).toBe(undefined);

let newStudent = data.createStudent;

// Check the link has been broken
Expand Down Expand Up @@ -150,7 +147,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 @@ -293,7 +290,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 @@ -313,7 +309,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 02f0805

Please sign in to comment.