Skip to content

Commit

Permalink
feat(postgraphql): add related fields to mutation top level for Relay 1
Browse files Browse the repository at this point in the history
  • Loading branch information
calebmer committed Oct 9, 2016
1 parent ee57864 commit 5977e8c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,10 @@ Object {
"integer": 2,
},
"tableMutation": Object {
"personByAuthorId": Object {
"id": 5,
"name": "Johnny Tucker",
},
"post": Object {
"__id": "WyJwb3N0cyIsNV0=",
"authorId": 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,9 @@ input TableMutationInput {
type TableMutationPayload {
clientMutationId: String
post: Post
# Reads a single \`Person\` that is related to this \`Post\`.
personByAuthorId: Person
query: Query
}
Expand Down Expand Up @@ -2874,6 +2877,9 @@ input TableMutationInput {
type TableMutationPayload {
clientMutationId: String
post: Post
# Reads a single \`Person\` that is related to this \`Post\`.
personByAuthorId: Person
query: Query
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mutation {
mult4(input: { arg0: 5, arg1: 2 }) { integer }
typesMutation(input: { a: 50, b: false, c: "xyz", d: [1, 2, 3], e: "{\"a\":1,\"b\":2,\"c\":3}", f: { start: { value: 1, inclusive: false }, end: { value: 5, inclusive: false } } }) { boolean }
compoundTypeMutation(input: { object: { a: 419, b: "easy cheesy baked potatoes", c: RED, fooBar: 8 } }) { compoundType { a b c d fooBar } }
tableMutation(input: { id: 5 }) { post { __id id headline authorId } }
tableMutation(input: { id: 5 }) { post { __id id headline authorId } personByAuthorId { id name } }
tableSetMutation(input: {}) { people { name } }
intSetMutation(input: { x: 5, z: 6 }) { integers }
noArgsMutation(input: { clientMutationId: "x" }) { clientMutationId integer }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { formatName } from '../../../../graphql/utils'
import BuildToken from '../../../../graphql/schema/BuildToken'
import createMutationGQLField from '../../../../graphql/schema/createMutationGQLField'
import transformGQLInputValue from '../../../../graphql/schema/transformGQLInputValue'
import createCollectionRelationTailGQLFieldEntries from '../../../../graphql/schema/collection/createCollectionRelationTailGQLFieldEntries'
import { sql } from '../../../../postgres/utils'
import { PGCatalog, PGCatalogProcedure } from '../../../../postgres/introspection'
import PGCollection from '../../../../postgres/inventory/collection/PGCollection'
import pgClientFromContext from '../../../../postgres/inventory/pgClientFromContext'
import transformPGValueIntoValue from '../../../../postgres/inventory/transformPGValueIntoValue'
import createPGProcedureFixtures from '../createPGProcedureFixtures'
Expand Down Expand Up @@ -42,8 +44,16 @@ function createPGProcedureMutationGQLFieldEntry (
pgCatalog: PGCatalog,
pgProcedure: PGCatalogProcedure,
): [string, GraphQLFieldConfig<mixed, mixed>] {
const { inventory } = buildToken
const fixtures = createPGProcedureFixtures(buildToken, pgCatalog, pgProcedure)

// See if the output type of this procedure is a single object, try to find a
// `PGCollection` which has the same type. If it exists we add some extra
// stuffs.
const pgCollection = !pgProcedure.returnsSet
? inventory.getCollections().find(collection => collection instanceof PGCollection && collection._pgClass.typeId === fixtures.return.pgType.id)
: null

// Create our GraphQL input fields users will use to input data into our
// procedure.
const inputFields = fixtures.args.map<[string, GraphQLInputFieldConfig<mixed>]>(
Expand Down Expand Up @@ -75,6 +85,10 @@ function createPGProcedureMutationGQLFieldEntry (

resolve: value => value,
}],

// Add related objects if there is an associated `PGCollection`. This
// helps in Relay 1.
...(pgCollection ? createCollectionRelationTailGQLFieldEntries(buildToken, pgCollection) : []),
],

// Actually execute the procedure here.
Expand Down

0 comments on commit 5977e8c

Please sign in to comment.