apollo-log icon indicating copy to clipboard operation
apollo-log copied to clipboard

Stringify call seems to unformat logs on Windows

Open edzillion opened this issue 3 years ago • 2 comments

  • apollo-server Version: [email protected]
  • Operating System (or Browser): windows 10, firefox latest
  • Node Version: v16.13.1
  • apollo-log Version: 1.1.0

How Do We Reproduce?

I suspect this is OS specific. To repro just use apollo-log as normal on a windows 10 machine. I am using conemu as my terminal but the same happens on windows default cmd

Expected Behavior

The logs are displayed with linebreaks etc so that they can be easily read.

apollo 44d6e2 {
  event: 'request',
  operationName: 'AddUser',
  query: 'mutation AddUser($addUserInput: AddUserInput!) {\n' +
    '  addUser(addUserInput: $addUserInput) {\n' +
    '    id\n' +
    '    device_id\n' +
    '    favourites\n' +
    '    __typename\n' +
    '  }\n' +
    '}',
  variables: [ 'addUserInput' ],
  context: {
    logger: Logger {
      name: 'apollo-server',
      levels: [Object],
      methodFactory: [Function: defaultMethodFactory],
      getLevel: [Function (anonymous)],
      setLevel: [Function (anonymous)],
      setDefaultLevel: [Function (anonymous)],
      resetLevel: [Function (anonymous)],
      enableAll: [Function (anonymous)],
      disableAll: [Function (anonymous)],
      trace: [Function: noop],
      debug: [Function: noop],
      info: [Function: bound info],
      warn: [Function: bound warn],
      error: [Function: bound error],
      log: [Function: noop]
    },
    schema: GraphQLSchema {
      __validationErrors: [],
      description: undefined,

Actual Behavior

Server is running on http://localhost:4000/graphql
apollo 21d17c {"event":"request","query":"    query IntrospectionQuery {      __schema {                queryType { name }        mutationType { name }        subscriptionType { name }        types {          ...FullType        }        directives {          name          description                    locations          args {            ...InputValue          }        }      }    }    fragment FullType on __Type {      kind      name      description            fields(includeDeprecated: true) {        name        description        args {          ...InputValue        }        type {          ...TypeRef        }        isDeprecated        deprecationReason      }      inputFields {        ...InputValue
  }      interfaces {        ...TypeRef      }      enumValues(includeDeprecated: true) {        name        description        isDeprecated        deprecationReason      }      possibleTypes {        ...TypeRef      }    }    fragment InputValue on __InputValue {      name      description      type { ...TypeRef }      defaultValue                }    fragment TypeRef on __Type {      kind      name      ofType {        kind        name        ofType {          kind
   name          ofType {            kind            name            ofType {              kind              name              ofType {                kind                name                ofType {                  kind
name                  ofType {

Observations

So the problem arises from the call to stringify() here:

https://github.com/shellscape/apollo-log/blob/0b33bcd29f17ca8d321586b4770fe1c779ff96cb/src/index.ts#L55

when I removed stringify() and just returned the mutated variable the formatting was correct (as shown in expected behaviour above). log[(data as any).errors ? 'error' : 'info'](chalk`{dim ${id}}`, mutated);

also I removed the line deleting newline chars in the query here

https://github.com/edzillion/apollo-log/blob/0b33bcd29f17ca8d321586b4770fe1c779ff96cb/src/index.ts#L69

edzillion avatar Jan 17 '22 11:01 edzillion

PRs are welcome

shellscape avatar Jan 17 '22 13:01 shellscape

@patrickblackjr please do not comment with "same, me too, +1, etc." that does nothing but spam the subscribers of this issue. basic github etiquette.

shellscape avatar Jan 25 '22 03:01 shellscape