import gql from 'graphql-tag';



export const schema = gql`
interface Node {
      id: ID!
}

# Pagination information. See https://facebook.github.io/relay/graphql/connections.htm#sec-undefined.PageInfo.
type PageInfo {
    # Whether there is a next page of nodes in the connection.
    hasNextPage: Boolean!
}

# Represents a null return value.
type EmptyResponse {
    # A dummy null value.
    alwaysNil: String
}

# A publisher of a registry extension.
#union RegistryPublisher = User | String
type RegistryPublisher {
    UserId: String
}


# A list of publishers of extensions in the registry.
type RegistryPublisherConnection {
    # A list of publishers.
    nodes: [RegistryPublisher!]!
    # The total count of publishers in the connection. This total count may be larger than the number of
    # nodes in the object when result is paginated.
    totalCount: Int!
    # Pagination information.
    pageInfo: PageInfo!
}

# The result of Mutation.extensionRegistry.createExtension.
type ExtensionRegistryCreateExtensionResult {
    # The newly created extension.
    extension: RegistryExtension!
}

# The result of Mutation.extensionRegistry.updateExtension.
type ExtensionRegistryUpdateExtensionResult {
    # The newly updated extension.
    extension: RegistryExtension!
}

# The result of Mutation.extensionRegistry.publishExtension.
type ExtensionRegistryPublishExtensionResult {
    # The extension that was just published.
    extension: RegistryExtension!
}

# An extenion's listing in the extension registry.
type RegistryExtension implements Node {
    # The unique, opaque, permanent ID of the extension. Do not display this ID to the user; display
    # RegistryExtension.extensionID instead (it is friendlier and still unique, but it can be renamed).
    id: ID!
    # The UUID of the extension. This identifies the extension externally (along with the origin). The UUID maps
    # 1-t0-1 to RegistryExtension.id.
    uuid: String!
    # The publisher of the extension. If this extension is from a remote registry, the publisher may be null.
    publisher: RegistryPublisher
    # The qualified, unique name that refers to this extension, consisting of the registry name (if non-default),
    # publisher's name, and the extension's name, all joined by "/" (for example, "cdecode/my-extension-name").
    extensionID: String!
    # The extension ID without the registry name.
    extensionIDWithoutRegistry: String!
    # The name of the extension (not including the publisher's name).
    name: String!
    # The extension manifest, or null if none is set.
    manifest: ExtensionManifest
    # The date when this extension was last updated on the registry.
    updatedAt: String
    # The URL to the extension on this CDECode site.
    url: String!
    # The URL to the extension on the extension registry where it lives (if this is a remote
    # extension). If this extension is local, then this field's value is null.
    remoteURL: String
    # Whether the registry extension is published on this CDECode site.
    isLocal: Boolean!
    # Whether the viewer has admin privileges on this registry extension.
    viewerCanAdminister: Boolean!
}

# A description of the extension, how to run or access it, and when to activate it.
type ExtensionManifest {
    # The raw JSON contents of the manifest.
    raw: String!
    # The title specified in the manifest, if any.
    title: String
    # The description specified in the manifest, if any.
    description: String
    # The URL to the bundled JavaScript source code for the extension, if any.
    bundleURL: String
    activationEvents: [String!]!
}

# A list of registry extensions.
type RegistryExtensionConnection {
    # A list of registry extensions.
    nodes: [RegistryExtension!]!
    # The total count of registry extensions in the connection. This total cound may be larger than the number of
    # nodes in this object when the result is paginated.
    totalCount: Int!
    # Pagination information
    pageInfo: PageInfo!
    # The URL to this list, or null if none exists.
    url: String
    # Errors that occured while communicating with remote registries to obtain the list of extensions.
    #
    # In order to be able to return local extensions even when the remote registry is unreachable, errors are
    # recorded here instead of in the top-level GraphQL errors list.
    error: String
}

# A CDECode product documentation page.
type DocSitePage {
    # The title of this page.
    title: String!
    # The content, as Markdown-rendered HTML.
    contentHTML: String!
    # The page index, as rendered HTML.
    indexHTML: String!
    # The filename of the file containing this page's content.
    filePath: String!
}


type Mutation {
    # Create a new extension in the extension registry.
    createExtension(
        # The ID of the extension's publisher (a user or organization).
        publisher: ID!
        # The name of the extension.
        name: String!
    ): ExtensionRegistryCreateExtensionResult!
    # Update an extension in the extension registry.
    #
    # Only authorized extension publishers may perform this mutation.
    updateExtension(
        # The extension to update.
        extension: ID!
        # The new name of the extension, or null or leave unchanged.
        name: String
    ): ExtensionRegistryUpdateExtensionResult!
    # Delete an extension from the extension registry.
    #
    # Only authorized extension publishers may perform this mutation.
    deleteExtension(
        # The ID of the extension to delete.
        extension: ID!
    ): EmptyResponse!
    # Publis an extension in the extension registry, creating it (if it doesn't yet exist) or updating it (if it
    # does).
    #
    # This is a helper that wraps multiple other GraphQL mutations to expose a single API for publishing an
    # extension.
    publishExtension(
        # The extension ID of the extension to publish. If a host prefix (ex., "cdebase.example.com/") is
        # needed and it is not included, it is automatically prepended.
        #
        # Examples: "alice/myextension", "acmecorp/myextension"
        extensionID: String!
        # The extension manifest (as JSON).
        manifest: String!
        # The bundled JavaScript source of the extension.
        bundle: String
        # The source map of the extension's JavaScript bundle, if any
        # The JavaScript bunle's "//#sourceMappingURL=" directive, if any, is ignored. When the bundle is served,
        # the source map provided here is referenced instead.
        sourceMap: String
        # Force publish even if there are warnings (such as invalid JSON warnings).
        force: Boolean = false
    ): ExtensionRegistryCreateExtensionResult!
}

type Query {
    # Find an extension by its extension ID (which is the concatenation of the publisher naem, a slash ("/"), and the extension name).
    #
    # To find an extension by its GraphQL ID, use Query.node
    extension(extensionID: String!): RegistryExtension
    # A list of extensions published in the extension registry.
    extensions(
        # Returns the first n extensions from the list.
        first: Int
        # Returns only extensions from this publisher.
        query: String
        # Include extensions from the local-registry.
        local: Boolean = true
        # Include extensions from remote registries.
        remote: Boolean = true
        # Sorts the list of extensions results such that the extensions with these IDs are first in the result set.
        #
        # Typically, the client passes the list of added and enabled extension IDs in this parameter so that the
        # results include those extensions first (which is typically what the user prefers).
        prioritizeExtensionIDs: [String!]
        # Include WIP (work-in-progress) extensions.
        includeWIP: Boolean = true
    ): RegistryExtensionConnection!
    # A list of publishers with at least 1 extension in the registry.
    publishers(
        # Return the first n publishers from the list.
        first: Int
    ): RegistryPublisherConnection!
    # A list of publishers that the viewer may publish extensions as.
    viewerPublishers: [RegistryPublisher!]!
    # The extension ID prefix for extensions that are published in the local extension registry. This is the
    # hostname ( and port, if non-default HTTP/HTTPS) of the CDEBase "appURL" site configuration property.
    #
    # It is null if extensions published on this CDEBase site do not have an extension ID prefix.
    #
    # Examples: "cdebase.example.com/", "cdebase.example.com:1234/"
    localExtensionIDPrefix: String
    # The CDECode documentation page for the given path, used to serve the content for help
    # pages under the URL path /help on the CDECode instance. If no page exists at the path,
    # null is returned.
    docSitePage(path: String!): DocSitePage
}
`;
