Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix when requiring a component in relation graph ql #5519

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 2 additions & 10 deletions docs/3.0.0-beta.x/plugins/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,7 @@ Return the second decade of users which have an email that contains `@strapi.io`

```graphql
query {
users(
limit: 10
start: 10
sort: "username:asc"
where: { email_contains: "@strapi.io" }
) {
users(limit: 10, start: 10, sort: "username:asc", where: { email_contains: "@strapi.io" }) {
username
email
}
Expand Down Expand Up @@ -720,10 +715,7 @@ module.exports = {
Mutation: {
createRestaurant: {
description: 'Create a new restaurant',
policies: [
'plugins::users-permissions.isAuthenticated',
'global::logging',
],
policies: ['plugins::users-permissions.isAuthenticated', 'global::logging'],
},
},
},
Expand Down
9 changes: 3 additions & 6 deletions packages/strapi-connector-bookshelf/lib/populate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ const populateFetch = (definition, options) => {
} else if (_.isEmpty(options.withRelated)) {
options.withRelated = populateComponents(definition);
} else {
options.withRelated = formatPopulateOptions(
definition,
options.withRelated
options.withRelated = formatPopulateOptions(definition, options.withRelated).concat(
populateComponents(definition)
);
}
};
Expand Down Expand Up @@ -173,9 +172,7 @@ const formatPopulateOptions = (definition, withRelated) => {
continue;
}

const assoc = tmpModel.associations.find(
association => association.alias === part
);
const assoc = tmpModel.associations.find(association => association.alias === part);

if (!assoc) return acc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ const Wrapper = styled.tr`
}
}
&.relation-row {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just undo the changes to this file as you did make any changes to it :)

background: linear-gradient(
135deg,
rgba(28, 93, 231, 0.05),
rgba(239, 243, 253, 0)
);
background: linear-gradient(135deg, rgba(28, 93, 231, 0.05), rgba(239, 243, 253, 0));
}
&.clickable {
&:hover {
Expand Down
92 changes: 86 additions & 6 deletions packages/strapi-plugin-graphql/test/graphqlRelations.test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,25 @@ let graphqlQuery;
let modelsUtils;

// utils
const selectFields = doc => _.pick(doc, ['id', 'name']);
const selectFields = doc => _.pick(doc, ['id', 'name', 'color']);

const rgbColorComponent = {
attributes: {
name: {
type: 'text',
},
red: {
type: 'integer',
},
green: {
type: 'integer',
},
blue: {
type: 'integer',
},
},
name: 'rgbColor',
};

const documentModel = {
attributes: {
Expand Down Expand Up @@ -37,6 +55,11 @@ const labelModel = {
target: 'application::document.document',
targetAttribute: 'labels',
},
color: {
type: 'component',
component: 'default.rgb-color',
repeatable: false,
},
},
connection: 'default',
name: 'label',
Expand Down Expand Up @@ -94,6 +117,7 @@ describe('Test Graphql Relations API End to End', () => {

modelsUtils = createModelsUtils({ rq });

await modelsUtils.createComponent(rgbColorComponent);
await modelsUtils.createContentTypes([documentModel, labelModel, carModel, personModel]);
}, 60000);

Expand All @@ -106,7 +130,11 @@ describe('Test Graphql Relations API End to End', () => {
people: [],
cars: [],
};
const labelsPayload = [{ name: 'label 1' }, { name: 'label 2' }];
const labelsPayload = [
{ name: 'label 1', color: null },
{ name: 'label 2', color: null },
{ name: 'labelWithColor', color: { name: 'tomato', red: 255, green: 99, blue: 71 } },
];
const documentsPayload = [{ name: 'document 1' }, { name: 'document 2' }];

test.each(labelsPayload)('Create label %o', async label => {
Expand All @@ -116,6 +144,12 @@ describe('Test Graphql Relations API End to End', () => {
createLabel(input: $input) {
label {
name
color {
name
red
green
blue
}
}
}
}
Expand All @@ -127,10 +161,8 @@ describe('Test Graphql Relations API End to End', () => {
},
});

const { body } = res;

expect(res.statusCode).toBe(200);
expect(body).toEqual({
expect(res.body).toEqual({
data: {
createLabel: {
label,
Expand All @@ -146,6 +178,12 @@ describe('Test Graphql Relations API End to End', () => {
labels {
id
name
color {
name
red
green
blue
}
}
}
`,
Expand All @@ -161,7 +199,7 @@ describe('Test Graphql Relations API End to End', () => {
});

// assign for later use
data.labels = res.body.data.labels;
data.labels = data.labels.concat(res.body.data.labels);
});

test.each(documentsPayload)('Create document linked to every labels %o', async document => {
Expand All @@ -174,6 +212,12 @@ describe('Test Graphql Relations API End to End', () => {
labels {
id
name
color {
name
red
green
blue
}
}
}
}
Expand Down Expand Up @@ -215,6 +259,12 @@ describe('Test Graphql Relations API End to End', () => {
labels {
id
name
color {
name
red
green
blue
}
}
}
}
Expand Down Expand Up @@ -246,6 +296,12 @@ describe('Test Graphql Relations API End to End', () => {
labels {
id
name
color {
name
red
green
blue
}
documents {
id
name
Expand Down Expand Up @@ -283,6 +339,12 @@ describe('Test Graphql Relations API End to End', () => {
labels {
id
name
color {
name
red
green
blue
}
}
}
}
Expand All @@ -309,6 +371,12 @@ describe('Test Graphql Relations API End to End', () => {
labels {
id
name
color {
name
red
green
blue
}
}
}
}
Expand Down Expand Up @@ -348,6 +416,12 @@ describe('Test Graphql Relations API End to End', () => {
label {
id
name
color {
name
red
green
blue
}
}
}
}
Expand Down Expand Up @@ -382,6 +456,12 @@ describe('Test Graphql Relations API End to End', () => {
labels {
id
name
color {
name
red
green
blue
}
}
}
}
Expand Down