-
Notifications
You must be signed in to change notification settings - Fork 79
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
Allow the Editor to fetch file details if the parent doesn't pass… #1225
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { graphqlTemplates } from 'lib/Injector'; | ||
|
||
const apolloConfig = { | ||
options({ fileId }) { | ||
return { | ||
variables: { | ||
rootFilter: { | ||
id: fileId | ||
}, | ||
}, | ||
}; | ||
}, | ||
props({ data: { error, readFiles, loading } }) { | ||
const file = (readFiles && readFiles.nodes[0]) ? readFiles.nodes[0] : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the only difference between v3.5 and 4. In 4, results are on the top level of |
||
const errors = error && error.graphQLErrors && | ||
error.graphQLErrors.map((graphQLError) => graphQLError.message); | ||
return { | ||
loading, | ||
file, | ||
graphQLErrors: errors | ||
}; | ||
}, | ||
}; | ||
|
||
const { READ } = graphqlTemplates; | ||
const query = { | ||
apolloConfig, | ||
templateName: READ, | ||
pluralName: 'Files', | ||
pagination: false, | ||
params: { | ||
rootFilter: 'FileFilterInput' | ||
}, | ||
args: { | ||
root: { | ||
filter: 'rootFilter' | ||
} | ||
}, | ||
fragments: [ | ||
'FileInterfaceFields', | ||
'FileFields', | ||
], | ||
fields: [ | ||
'nodes', [ | ||
'...FileInterfaceFields', | ||
'...FileFields' | ||
], | ||
], | ||
}; | ||
|
||
|
||
export default query; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { graphqlTemplates } from 'lib/Injector'; | ||
|
||
/** | ||
* Query to fetch a single file by its ID. The resulting file will be pass to your component | ||
* under a `file` prop. `null` will be pass if the specified ID does not exist. | ||
*/ | ||
const apolloConfig = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file mostly copies We're still using the same graphQL endpoint to retrieve our single file. Maybe we should create an actual readOneFile query server side. Not sure if that's advisable. |
||
options({ fileId }) { | ||
return { | ||
variables: { | ||
rootFilter: { | ||
id: fileId | ||
}, | ||
}, | ||
}; | ||
}, | ||
props({ data: { error, readFiles, loading: networkLoading } }) { | ||
const file = readFiles ? readFiles[0] : null; | ||
emteknetnz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const errors = error && error.graphQLErrors && | ||
error.graphQLErrors.map((graphQLError) => graphQLError.message); | ||
return { | ||
loading: networkLoading, | ||
file, | ||
graphQLErrors: errors, | ||
}; | ||
}, | ||
}; | ||
|
||
const { READ } = graphqlTemplates; | ||
const query = { | ||
apolloConfig, | ||
templateName: READ, | ||
pluralName: 'Files', | ||
pagination: false, | ||
params: { | ||
rootFilter: 'FileFilterInput', | ||
}, | ||
args: { | ||
root: { | ||
filter: 'rootFilter' | ||
} | ||
}, | ||
fragments: [ | ||
'FileInterfaceFields', | ||
'FileFields', | ||
], | ||
fields: [ | ||
'...FileInterfaceFields', | ||
'...FileFields', | ||
], | ||
maxime-rainville marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
|
||
export default query; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed this to
fileId
. This avoids us having to do gymnastic to change the prop fromtargetId
tofileID
when we pass it to the graphQL query and it just makes more sense since the target will always be a file ID any way.