Skip to content

Commit

Permalink
refactor(graphql): rename __id to nodeId (graphile#327)
Browse files Browse the repository at this point in the history
* increase version range again

* rename __id to nodeId
  • Loading branch information
calebmer committed Feb 11, 2017
1 parent 0617e7a commit 6f4fea7
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 237 deletions.
4 changes: 2 additions & 2 deletions docs/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Arguments include:
- **`pgConfig`**: An object or string that will be passed to the [`pg`][] library and used to connect to a PostgreSQL backend.
- **`schemaName`**: A string which specifies the PostgreSQL schema you will be serving with PostGraphQL. The default schema is the `public` schema. May be an array for multiple schemas.
- **`options`**: An object containing other miscellaneous options. Options could be:
- `classicIds`: Enables classic ids for Relay 1 support. Instead of using the field name `__id` for globally unique ids, PostGraphQL will instead use the field name `id` for its globally unique ids. This means that table `id` columns will also get renamed to `rowId`.
- `classicIds`: Enables classic ids for Relay 1 support. Instead of using the field name `nodeId` for globally unique ids, PostGraphQL will instead use the field name `id` for its globally unique ids. This means that table `id` columns will also get renamed to `rowId`.
- `dynamicJson`: Setting this to `true` enables dynamic JSON which will allow you to use any JSON as input and get any arbitrary JSON as output. By default JSON types are just a JSON string.
- `disableDefaultMutations`: Setting this to `true` will prevent the creation of the default mutation types & fields. Database mutation will only be possible through Postgres functions.
- `graphiql`: Set this to `true` to enable the GraphiQL interface.
Expand Down Expand Up @@ -129,7 +129,7 @@ Arguments include:
- **`pgConfig`**: An object or string that will be passed to the [`pg`][] library and used to connect to a PostgreSQL backend. If you already have a client or pool instance, when using this function you may also pass a `pg` client or a `pg-pool` instance directly instead of a config.
- **`schemaName`**: A string which specifies the PostgreSQL schema that PostGraphQL will use to create a GraphQL schema. The default schema is the `public` schema. May be an array for multiple schemas. For users who want to run the Postgres introspection query ahead of time, you may also pass in a `PgCatalog` instance directly.
- **`options`**: An object containing other miscellaneous options. Most options are shared with the `postgraphql` middleware function. Options could be:
- `classicIds`: Enables classic ids for Relay 1 support. Instead of using the field name `__id` for globally unique ids, PostGraphQL will instead use the field name `id` for its globally unique ids. This means that table `id` columns will also get renamed to `rowId`.
- `classicIds`: Enables classic ids for Relay 1 support. Instead of using the field name `nodeId` for globally unique ids, PostGraphQL will instead use the field name `id` for its globally unique ids. This means that table `id` columns will also get renamed to `rowId`.
- `dynamicJson`: Setting this to `true` enables dynamic JSON which will allow you to use any JSON as input and get any arbitrary JSON as output. By default JSON types are just a JSON string.
- `jwtSecret`: The JWT secret that will be used to sign tokens returned by the type created with the `jwtPgTypeIdentifier` option.
- `jwtPgTypeIdentifier`: The Postgres type identifier for the compound type which will be signed as a JWT token if ever found as the return type of a procedure. Can be of the form: `my_schema.my_type`. You may use quotes as needed: `"my-special-schema".my_type`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dataloader": "^1.2.0",
"debug": "^2.3.3",
"finalhandler": "^0.5.1",
"graphql": ">=0.6.0 <0.9.0",
"graphql": ">=0.6.0 <1.0.0",
"http-errors": "^1.5.1",
"jsonwebtoken": "^7.1.9",
"parseurl": "^1.3.1",
Expand Down
22 changes: 11 additions & 11 deletions src/graphql/__tests__/__snapshots__/graphqlIntegration-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ input DeletePersonInput {
clientMutationId: String
# The globally unique \`ID\` which will identify a single \`Person\` to be deleted.
__id: ID!
nodeId: ID!
}
# The output of our \`deletePerson\` mutation.
Expand Down Expand Up @@ -112,7 +112,7 @@ input DeletePostInput {
clientMutationId: String
# The globally unique \`ID\` which will identify a single \`Post\` to be deleted.
__id: ID!
nodeId: ID!
}
# The output of our \`deletePost\` mutation.
Expand Down Expand Up @@ -204,7 +204,7 @@ type Mutation {
# An object with a globally unique \`ID\`.
interface Node {
# A globally unique identifier. Can be used in various places throughout the system to identify this single value.
__id: ID!
nodeId: ID!
}
# Information about pagination in a connection.
Expand Down Expand Up @@ -260,7 +260,7 @@ enum PeopleOrderBy {
type Person implements Node {
# A globally unique identifier. Can be used in various places throughout the system to identify this single value.
__id: ID!
nodeId: ID!
id: Int!
name: String!
email: Email!
Expand Down Expand Up @@ -311,7 +311,7 @@ input PersonPatch {
type Post implements Node {
# A globally unique identifier. Can be used in various places throughout the system to identify this single value.
__id: ID!
nodeId: ID!
id: Int!
authorId: Int!
status: PostStatus!
Expand Down Expand Up @@ -403,7 +403,7 @@ type Query implements Node {
# Fetches an object given its globally unique \`ID\`.
node(
# The globally unique \`ID\`.
__id: ID!
nodeId: ID!
): Node
# Reads and enables paginatation through a set of \`Person\`.
Expand Down Expand Up @@ -434,7 +434,7 @@ type Query implements Node {
# Reads a single \`Person\` using its globally unique \`ID\`.
person(
# The globally unique \`ID\` to be used in selecting a single \`Person\`.
__id: ID!
nodeId: ID!
): Person
personById(
# The \`Int\` to use when reading a single value.
Expand Down Expand Up @@ -477,7 +477,7 @@ type Query implements Node {
# Reads a single \`Post\` using its globally unique \`ID\`.
post(
# The globally unique \`ID\` to be used in selecting a single \`Post\`.
__id: ID!
nodeId: ID!
): Post
postById(
# The \`Int\` to use when reading a single value.
Expand All @@ -489,7 +489,7 @@ type Query implements Node {
query: Query!
# The root query type must be a \`Node\` to work well with Relay 1 mutations. This just resolves to \`query\`.
__id: ID!
nodeId: ID!
}
# All input for the \`updatePersonByEmail\` mutation.
Expand Down Expand Up @@ -525,7 +525,7 @@ input UpdatePersonInput {
clientMutationId: String
# The globally unique \`ID\` which will identify a single \`Person\` to be updated.
__id: ID!
nodeId: ID!
# An object where the defined keys will be set on the \`Person\` identified by our globally unique \`ID\`.
personPatch: PersonPatch!
Expand Down Expand Up @@ -562,7 +562,7 @@ input UpdatePostInput {
clientMutationId: String
# The globally unique \`ID\` which will identify a single \`Post\` to be updated.
__id: ID!
nodeId: ID!
# An object where the defined keys will be set on the \`Post\` identified by our globally unique \`ID\`.
postPatch: PostPatch!
Expand Down
5 changes: 2 additions & 3 deletions src/graphql/schema/BuildToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ interface BuildToken {
readonly inventory: Inventory,
// Some options we can use to configure how we build our GraphQL schema.
readonly options: {
// Changes the name of the node field id on the `Node` interface. Relay 1,
// for example, wants the name to be `id`. Soon in the GraphQL spec, an
// `__id` field will be standardized.
// Changes the name of the node field id on the node interface. Relay 1,
// for example, wants the name to be `id`.
readonly nodeIdFieldName: string,
// By default, JSON is output as a string in our GraphQL queries. If true
// then JSON will be output as a dynamic object.
Expand Down
7 changes: 3 additions & 4 deletions src/graphql/schema/createGqlSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import getQueryGqlType from './getQueryGqlType'
import getMutationGqlType from './getMutationGqlType'

export type SchemaOptions = {
// The exact name for the node id field. In the past Relay wanted this to
// be `id`, but there are some movements in the GraphQL standard to
// standardize an `__id` field.
// Changes the name of the node field id on the node interface. Relay 1,
// for example, wants the name to be `id`.
nodeIdFieldName?: string,
// If true then any literal will be accepted to this type and its output will
// be plain JSON.
Expand All @@ -34,7 +33,7 @@ export default function createGqlSchema (inventory: Inventory, options: SchemaOp
const buildToken: BuildToken = {
inventory,
options: {
nodeIdFieldName: options.nodeIdFieldName || '__id',
nodeIdFieldName: options.nodeIdFieldName || 'nodeId',
dynamicJson: options.dynamicJson || false,
disableDefaultMutations: options.disableDefaultMutations || false,
},
Expand Down
Loading

0 comments on commit 6f4fea7

Please sign in to comment.